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

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);

  效果:js 日期转字符串 时间类型转换_第1张图片

 

  

//核心代码---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

  效果:js 日期转字符串 时间类型转换_第2张图片

你可能感兴趣的:(前端)