js时间戳转化为时间

来源:互联网 发布:star法则简历模板java 编辑:程序博客网 时间:2024/04/30 20:46
<!DOCTYPE html><html><head><title>时间戳</title><meta charset="utf-8"></head><body><script type="text/javascript">//getTime 返回1970年1月1日午夜到现在的毫秒数//javascript中的toString()方法,主要用于Array、Boolean、Date、Error、Function、Number等对象//<!-- Date.parse( "2000-01-01" ) IE and Mozilla浏览器: "NaN"。//那么我们一般在Web页面上显示的时间就不能直接转换。需要做处理。 //可以直接转换的格式"01/01/2000","2000/01/01"  -->//stringObject.substr(start,length)function get_unix_time(dateStr){    var newstr = dateStr.replace(/-/g,'/');     var date =  new Date(newstr);    console.log(date);//Thu May 08 2014 00:22:11 GMT+0800 (中国标准时间)    var time_str = date.getTime().toString();    console.log(time_str);//1399479731000因为只有到秒所有后面的可以考虑不要 1秒=1000毫秒    return time_str.substr(0, 10);//1399479731 }console.log(get_unix_time("2014-05-08 00:22:11"));</script></body></html>

0 0