[英]How to keep the timezone offset of the utc dates with luxon?
I'm trying to print multiple dates that are stored with their own timezone off-set.我正在尝试打印以自己的时区偏移量存储的多个日期。
Using momentjs, I used to do the following使用momentjs,我曾经做过以下
const date1 = "2013-01-01T00:00:00-05:00";
const date2 = "2013-01-01T00:00:00-13:00";
console.log(moment.parseZone(date1).format());
console.log(moment.parseZone(date2).format());
// 2013-01-01T00:00:00-05:00
// 2013-01-01T00:00:00-13:00
which prints both dates with their offset ( -05:00
and -13:00
).它打印两个日期及其偏移量( -05:00
和-13:00
)。
I would like to do the same with luxon js我想用 luxon js 做同样的事情
const date1 = "2013-01-01T00:00:00-05:00";
const date2 = "2013-01-01T00:00:00-13:00";
console.log(luxon.DateTime.fromISO(date1).toISO());
console.log(luxon.DateTime.fromISO(date2).toISO());
// 2013-01-01T02:00:00.000-03:00
// 2013-01-01T10:00:00.000-03:00
But instead of keeping the offset seems like it's converting them to -03:00
.但似乎不是保持偏移量,而是将它们转换为-03:00
。 How can I keep the same off set?我怎样才能保持相同的偏移量?
Just found the answer.刚刚找到答案。 I need to activate the setZone
option.我需要激活setZone
选项。 So, the solution will be as follow:因此,解决方案如下:
const date1 = "2013-01-01T00:00:00-05:00";
const date2 = "2013-01-01T00:00:00-13:00";
console.log(luxon.DateTime.fromISO(date1, { setZone: true }).toISO());
console.log(luxon.DateTime.fromISO(date2, { setZone: true }).toISO());
// 2013-01-01T00:00:00.000-05:00
// 2013-01-01T00:00:00.000-13:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.