使用moment-timezone
和America/Sao_Paulo
尝试解析偏移量为America/Sao_Paulo
的日期时出现错误。我创建了以下代码:
const date = "2019-1-1 23:30";
const format = "YYYY-M-D HH:mm";
const timezone = "America/Sao_Paulo";
const dateMoment = moment.tz(date, format, timezone);
dateMoment
的输出为2019-01-01T23:30:00-02:00
,但我期望2019-01-01T23:30:00-03:00
,因为America/Sao_Paulo
的偏移量为-03:00
。
我遗漏了某些东西还是我初始化dateMoment
错了吗?
const date = "2019-1-1 23:30";
const format = "YYYY-M-D HH:mm";
const timezone = "America/Sao_Paulo";
const dateMoment = moment.tz(date, format, timezone);
console.log(dateMoment.format());
console.log(moment.tz(timezone).format('Z'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script type="text/javascript" src="http://momentjs.com/downloads/moment-timezone-with-data.js"></script>