javascript 取得当前 yyyymmdd

这里有一个答案,http://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object

Altered piece of code I often use:

Date.prototype.yyyymmdd = function() {
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();

return [this.getFullYear(), !mm[1] && ‘0’, mm, !dd[1] && ‘0’, dd].join(”); // padding
};

var date = new Date();
date.yyyymmdd();

赞同高达 300 多票,然而,请注意,在 2016.7.10 时,这个函数会输出:201607010

所以,估计坑死一片爹

下面的这个答案:http://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object/16714931#16714931

才是对的

====================

2016-7-11 00:27:04 上述也有问题,iso 时间是伦敦时间

看这里 http://stackoverflow.com/quest…

Leave a Reply

Your email address will not be published. Required fields are marked *