-
I still get a // My local time: Fri Nov 12 2021 17:39:36 GMT+0800 (China Standard Time)
let t = OffsetDateTime::now_utc().replace_offset(UtcOffset::from_hms(8, 0, 0).unwrap())
t.unix_timestamp(); // 1636681176
// JS
// new Date(1636681176000)
// Fri Nov 12 2021 09:39:36 GMT+0800 (China Standard Time) pub const fn unix_timestamp(self) -> i64 {
let days =
(self.utc_datetime.to_julian_day() as i64 - UNIX_EPOCH_JULIAN_DAY as i64) * 86_400;
let hours = self.utc_datetime.hour() as i64 * 3_600;
let minutes = self.utc_datetime.minute() as i64 * 60;
let seconds = self.utc_datetime.second() as i64;
days + hours + minutes + seconds
} |
Beta Was this translation helpful? Give feedback.
Answered by
jhpratt
Nov 12, 2021
Replies: 1 comment 6 replies
-
The Unix timestamp is by definition UTC and does not need to take the UTC offset into account. |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
jhpratt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Unix timestamp is by definition UTC and does not need to take the UTC offset into account.