js中时间的格式化

var dt = new Date();
dt.setDate(26);
dt.setMonth(7);
dt.setYear(2015);
dt.setHours(21);
dt.setMinutes(46);

document.writeln(dt.toString() + " <br />");
document.writeln(dt.toLocaleString() + " <br />");
document.writeln(dt.toLocaleDateString() + " <br />");
document.writeln(dt.toLocaleTimeString() + " <br />");
document.writeln(dt.toGMTString() + " <br />");
document.writeln(dt.toUTCString() + " <br />");

结果为:

Wed Aug 26 2015 21:46:05 GMT+0800
2015/8/26 下午9:46:05
2015/8/26
下午9:46:05
Wed, 26 Aug 2015 13:46:05 GMT
Wed, 26 Aug 2015 13:46:05 GMT

原文地址:https://www.cnblogs.com/lswit/p/4678805.html