javascript - 在时刻 js 上使用 endOf('quarter') 后时区发生变化
问题描述
我正在使用以下方法来结束一个季度:
function convertToMomentDates(dates) {
return dates.map((date) => moment(date).tz("Europe/Rome"));
}
function getEndOfQuarter(dates) {
const lastDate = dates.pop();
if (!lastDate || !lastDate.isValid()) return null;
console.log(lastDate.endOf("quarter").format());
return lastDate.endOf("quarter").format();
}
const dates = [
"2018-10-01T01:00:00+01:00",
"2019-01-01T01:00:00+01:00",
];
const endOfQuarterResult = getEndOfQuarter(convertToMomentDates(dates));
console.log(
endOfQuarterResult ===
"2019-03-31T23:59:59+01:00"
);
document.getElementById('result').innerHTML = endOfQuarterResult;
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.14/moment-timezone-with-data.min.js"></script>
<div id="result"></div>
我的意思是我正在使用带有 +1:00 偏移量的所有日期,并且在 endOf 函数之后它被更改为 +2:00,为了不改变偏移量,正确的实现是什么......
解决方案
在这种情况下,由于 3 月底的意大利/罗马时区,预期结果是可以的,在这种情况下,最后一个季度末,偏移量变为 +2。更多信息可以在这个网址上看到:https ://www.timeanddate.com/time/zone/italy/rome 。
推荐阅读
- excel - 结合 COUNTIF 和 VLOOKUP
- javascript - Ionic 3 使用网格在右侧离子输入内部带有图标
- java - 区块链技术如何验证工作量证明
- javascript - Angular 6 中的动态属性评估
- apache-kafka - Apache Nifi 中的 publishKafka 处理器中的多个 kafka 主题
- python - Python:有点请求
- jquery - 解析通过jquery中的ajax获得的json响应后如何进行foreach?
- java - 不幸的是,应用程序已停止并导致 E/installd: system dir 0 : /system/app/
- angularjs - 使用 Angular js 调用 WEB API 时出现 CORS 问题
- javascript - 在 GridX 中禁用“单击标题”排序