有没有简单的方法将字符串“YYYYMMDDHHMMSS”转换为“YYYY / MM / DD HH:MM:SS”?
例如我有
var date_string = "20121231023350";
我希望输出为
new_date_string = "2012/12/31 02:33:50";
答案 0 :(得分:6)
"20121231023350".replace(
/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/,
"$1/$2/$3 $4:$5:$6"); // "2012/12/31 02:33:50"
答案 1 :(得分:3)
function ConvertTime(OldTime)
{
if(OldTime.length != 14)
return "Error";
return OldTime.substring(0,4) + "/" + OldTime.substring(4,6) + "/" + OldTime.substring(6,8) + " " + OldTime.substring(8,10) + ":" + OldTime.substring(10,12) + ":" + OldTime.substring(12,14);
}
ConvertTime("20121231023350");
答案 2 :(得分:1)