<meta charset="utf-8">
<script>
function double_to_stamp(str_time){
var new_str = str_time.replace(/:/g,'-');
new_str = new_str.replace(/ /g,'-');
var arr = new_str.split("-");
var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));
return strtotime = datum.getTime()/1000;
}
function stamp_to_double(unixtime) {
var timestr = new Date(parseInt(unixtime) * 1000);
var datetime = timestr.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
return datetime;
}
var stamp = double_to_stamp( '2017-05-11 19:10:00');
document.write("<br><b>转换后的UNIX时间戳为</b>: "+stamp);
var date_time = stamp_to_double('1494500293');
document.write("<br><b>转换后的日期为</b>: "+date_time);
</script>
转载自:http://blog.sina.com.cn/s/blog_9300785001012khh.html