首页 > 代码库 > JS将日期转化为unix时间戳

JS将日期转化为unix时间戳

var str = ‘2008-10-09 21:35:28‘;//PHP中对应的UNIX时间戳为1223559328var new_str = str.replace(/:/g,‘-‘);new_str = new_str.replace(/ /g,‘-‘);var arr = new_str.split("-");document.write("<b>原始日期</b>: "+str);var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));document.write("<br><b>转换后的UNIX时间戳为</b>: "+(datum.getTime()/1000));var datum = new Date(datum.getTime());document.write("<br><b>还原到原始日期为</b>: "+datum.toLocaleString());