先说一下我知道的 JS 几种类型:
标准格式转时间戳
var timeA = new Date(); //timeA标准时间 var timeB = time.getTime() //timeB时间戳
时间戳转标准格式
var timeA= new Date(timeB) //timeA 标准时间,timeB时间戳
标准时间转显示的格式
var format = function(time, format){ var t = new Date(time); var tf = function(i){return (i < 10 ? '0' : '') + i}; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){ switch(a){ case 'yyyy': return tf(t.getFullYear()); break; case 'MM': return tf(t.getMonth() + 1); break; case 'mm': return tf(t.getMinutes()); break; case 'dd': return tf(t.getDate()); break; case 'HH': return tf(t.getHours()); break; case 'ss': return tf(t.getSeconds()); break; } })} var timeC = format(timeA, 'yyyy-MM-dd HH:ss'); //timeC界面显示格式
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did311