js 日期转字符串 时间类型转换

var draftTimeV = "Fri Mar 10 09:44:48 CST 2017";    <!--  示例 -->

  

  //核心代码---state

  draftTimeV = draftTimeV + "";
  var date = "";
  var month = new Array();
  month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4; month["May"] = 5; month["Jan"] = 6;
  month["Jul"] = 7; month["Aug"] = 8; month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12;

  str = draftTimeV.split(" ");
  date = str[5] + "-";
  date = date + month[str[1]] + "-" + str[2];

  //------end

  alert(date);

  效果:

 

  

//核心代码---state

  draftTimeV = draftTimeV + "";
  var date = "";
  var month = new Array();
  month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4; month["May"] = 5; month["Jan"] = 6;
  month["Jul"] = 7; month["Aug"] = 8; month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12;

  str = draftTimeV.split(" ");
  date = str[5] + "-";
  date = date + month[str[1]] + "-" + str[2]+" "+str[3];

  //------end

  效果:

posted @ 2017-03-10 10:21  举个栗子-  阅读(8753)  评论(0编辑  收藏  举报