Skip to content

Some Luxon zone offsets seem to be incorrect #1478

Answered by diesieben07
alberthtan asked this question in Q&A
Discussion options

You must be logged in to vote

now.millisecond is a value between 0 and 999 denoting the fractional milliseconds of the DateTime. Zone#formatOffset expects a unix timestamp in milliseconds. Therefor your code will always format the offset on some fractional offset within the first second of 1970/01/01. At this point Asia/Singapore was at offset +7:30, the zone was only shifted to +8:00 in 1982.
If you pass the correct timestamp to formatOffset you will receive the correct offset.

Edit: to get the unix timestamp in millseconds from a DateTime use DateTime#valueOf or DateTime#toMillis.

Edit again: I jused noticed that in your code you are using luxonDateObject.setZone("Singapore") without using the return value. Luxon's …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@alberthtan
Comment options

@diesieben07
Comment options

Answer selected by alberthtan
@alberthtan
Comment options

@alberthtan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants