Javascript date differs based on month format
This question already has an answer here:
As indicated on MDN, using the Date constructor to parse dates is discouraged because of implementation differences.
However, if you really want to do so, the only solution is to ensure that the inputs you provide are consistent. This will ensure that (at least within a single environment) the outputs will be consistent.
To have both work like 2017-5-19
:
function adjustDateString(str) {
return str.split('-').map(Number).join('-');
}
console.log(new Date(adjustDateString('2017-5-19')))
console.log(new Date(adjustDateString('2017-05-19')))
链接地址: http://www.djcxy.com/p/18632.html