对CST格式的时间字符串进行分段截取,重新拼接为GMT格式
//Thu Aug 18 20:38:54 CST 2016,时间格式转换
//输出格式:yyyy-MM-dd HH:mm:ss
Thu Aug 18 2016 20:38:54 GMT+0800
function getTaskTime(strDate) {
if(null==strDate || ""==strDate){
return "";
}
var dateStr=strDate.trim().split(" ");
var strGMT = dateStr[0]+" "+dateStr[1]+" "+dateStr[2]+" "+dateStr[5]+" "+dateStr[3]+" GMT+0800";
var date = new Date(Date.parse(strGMT));
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
var minute = date.getMinutes();
minute = minute < 10 ? ('0' + minute) : minute;
var second = date.getSeconds();
second = second < 10 ? ('0' + second) : second;
return y+"-"+m+"-"+d+" "+h+":"+minute+":"+second;
};
显示结果:
原始时间格式:Thu Aug 18 20:38:54 CST 2016
GMT时间格式:Thu Aug 18 2016 20:38:54 GMT+0800 (中国标准时间)
转换时间格式:2016-08-18 20:38:54