JS 时间转换为时间戳

 1 Date.prototype.format = function(fmt) {
 2     var o = {
 3         "M+" : this.getMonth()+1,                 //月份
 4         "d+" : this.getDate(),                    //
 5         "h+" : this.getHours(),                   //小时
 6         "m+" : this.getMinutes(),                 //
 7         "s+" : this.getSeconds(),                 //秒        "q+" : Math.floor((this.getMonth()+3)/3), //季度
 8         "S"  : this.getMilliseconds()             //毫秒
 9     };
10     if(/(y+)/.test(fmt)) {
11         fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
12     }
13     for(var k in o) {
14         if(new RegExp("("+ k +")").test(fmt)){
15             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
16         }
17     }
18     return fmt;
19 }
temp = '2016-8-10 10:00:00'
date_1 = new Date(new Date(temp).getTime()).format("MM-dd hh:mm:ss"); # 将年份去掉了
原文地址:https://www.cnblogs.com/BigStupid/p/8270567.html