js 日期转字符串 时间类型转换
Posted 举个栗子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
效果:
以上是关于js 日期转字符串 时间类型转换的主要内容,如果未能解决你的问题,请参考以下文章