Date() in different timezone #1416
Replies: 6 comments
-
Posted at 2020-07-01 by @gfwilliams There's no way built into If it is then show me where and I'll be happy to add it to Espruino though. You could change the timezone globally just while you access date:
But IMO the most sane thing is just to add/subtract what you need from the hours: var timezone = 1;
var d = new Date(Date.now()+timezone*3600000);
print(new Date(), d)
// Date: Wed Jul 1 2020 08:14:48 GMT+0000
// Date: Wed Jul 1 2020 09:14:48 GMT+0000 It'll still report |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-01 by Michaelnik This lib looks quite sane https://momentjs.com/timezone/ (MIT license). Is there a way to include something like that?
For me js is still mystery so no idea where .format() in the above comes from... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-02 by Michaelnik Hmm, in emulator I get
Another problem I run into changing timezone in E and resetting is to pull another Date is I have to pull Date 2 times and the minutes could be off (59 in one, 00 in other).... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-03 by @gfwilliams Just changed the above - it should be But honestly I'd just use the second option... It's a bit cleaner IMO.
I'm not sure I understand? Once you have |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-03 by Michaelnik I want to display consistent:
The below works in emu (to show current tz and UTC) but only for the short time using E approach (but what if to new Date() calls span the minute...i.e one is in prev minute, other is in the next?). For the second approach the added value would be 0 for UTC but it does not work....
Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-03 by @gfwilliams Is the issue with the second approach just that your timezone is already nonzero, so what you need is just:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2020-06-30 by Michaelnik
I wanted to add clock in a different tz (on bangle.js). I looked at Date() and it has no API to obtain Date in custom tz, is that right?
Timezones could also be useful for setting clock offset which is now an unfriendly number.
M
Beta Was this translation helpful? Give feedback.
All reactions