Replies: 3 comments 12 replies
-
Isn't the thing about Unix timestamp that it is always based on UTC? Making it timezone relative would make it ambiguous which defeats a main benefit of a Unix timestamp.... |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I've done some work on rewriting this in JavaScript; I can open a PR if you'd like! I'm not sure how you'd want the localization enhancement handled, though:
The current behavior can be replicated with something like this: let fromUnix = new Date(1535438729 * 1000)
let [date, _, time] = fromUnix.toISOString().split(/(\.|T)/)
`${date} ${time} UTC`
// "2018-08-28 06:45:29 UTC" With a customizable system// for Intl.DateTimeFormat
let options = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
timeZoneName: 'short',
} Default optionThe current behavior would require setting a locale which just happens to use YYYY-MM-DD, rather than one which is actually true for the user, (because reasons). Something like one of these:
System optionAn empty array of locales and no timeZone key under 'options' yields something akin to "use current location" perhaps:
Mix-and-match optionThere are various ways that locales handle naming local vs non-local timezones: new Intl.DateTimeFormat("af", {timeZone: "America/New_York", ...options}).format(fromUnix)
// "2018-08-28 02:45:29 GMT-4"
new Intl.DateTimeFormat("zh", {timeZone: "America/New_York", ...options}).format(fromUnix)
// "2018/08/28 GMT-4 02:45:29"
new Intl.DateTimeFormat("fr-CH", {timeZone: "America/New_York", ...options}).format(fromUnix)
// "28.08.2018, 02:45:29 UTC−4"
new Intl.DateTimeFormat("zh-HK", {timeZone: "America/New_York", ...options}).format(fromUnix)
// "28/08/2018 02:45:29 [EDT]"
new Intl.DateTimeFormat("zh", {timeZone: "Asia/Shanghai", ...options}).format(fromUnix)
// "2018/08/28 GMT+8 14:45:29"
new Intl.DateTimeFormat("af", {timeZone: "Africa/Johannesburg", ...options}).format(fromUnix)
// "2018-08-28 08:45:29 SAST" So in order to get something localized but otherwise in the style of the current behavior, what I would do is: new Intl.DateTimeFormat("en-CA", options).format(fromUnix).replace(',', '')
// "2018-08-28 02:45:29 EDT" |
Beta Was this translation helpful? Give feedback.
-
I am using the popclip plugin, thank you very much for your development, there is a question about the UTC plugin, can you read the local time zone like the timestamp plugin. Thank you very much if you can solve it 🙏
Beta Was this translation helpful? Give feedback.
All reactions