我有一个功能,可以获得范围内的所有日子:
function getDates(inicio, fim, isMoment = false) {
inicio = moment.utc(inicio); //new Date(inicio);
fim = moment.utc(fim); //new Date(fim);
var dias = [];
var atual = inicio;
while(atual.utc() <= fim){
dias.push(atual.format("YYYY-MM-DD"));
//dias.push(moment.utc(atual.format("YYYY-MM-DD")));
//dias.push(atual.clone().tz("America/Sao_Paulo"));//America/Sao_Paulo
atual.add(1, "d");
}
if(isMoment){
var i;
var result = [];
for(i = 0; i < dias.length; i++){
//console.log(i +" - " +dias[i]);
result.push(moment(dias[i]));
}
return result;
}
return dias;
}
//Tested with:
var a = getDates("2016-01-01", "2016-12-31", true);
console.log(a[365].toDate());
<script src="//momentjs.com/downloads/moment.min.js"></script>
Chrome / Opera结果:Fri Dec 30 2016 22:00:00 GMT-0200 (Horário brasileiro de verão)
Firefox结果:Date 2016-12-31T00:00:00.000Z
这是V8或SpiderMonkey的问题 - 谁是Wight,V8总是使用实时或SM来使用开发人员的给定日期?有没有办法让所有过程忽略夏令时?