`new Date(ts).toLocaleString()` 在 Windows (2015/9/1)、iOS (2015年9月1)、Android (Tue Sep 01) 格式各異。
`toLocaleString` 依賴**宿主環境區域設置**,ECMA 標準未強制統一格式。
function formatDate(ts) {
var d = new Date(ts);
return d.getFullYear() + '/' + (d.getMonth()+1) + '/' + d.getDate()
+ ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
}
Date.prototype.toLocaleString = function() {
return this.getFullYear()+'-'+(this.getMonth()+1)+'-'+this.getDate()
+' '+this.getHours()+':'+this.getMinutes()+':'+this.getSeconds();
};
跨平台統一格式**不要依賴 toLocaleString**,自行格式化或引入輕量庫。