New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to keep backend timezone? #4799
Comments
Afaik, moment defaults to using the device's timezone when formatting a date (which is also the standard behaviour of Javascript). So yes, formatting a date should depend on the environment. For example, on my device I get this for your date, which is the correct time for my local time (Auckland): moment("2018-10-10T13:00:00+11:00").format()
// => '2018-10-10T15:00:00+13:00' If you want to set a default timezone for the user manually, you can use moment.tz.setDefault('America/New_York'); That will enforce all formatting to be done for that timezone and be independent of the environment. Here's a link to the docs: https://momentjs.com/timezone/docs/#/using-timezones/default-timezone/ It's not possible to find out the user's timezone from the offset (because multiple timezones can share the same offset, e. g. depending on daylight saving time) but you can use the Then you can print a single date in a certain timezone by using e. g. moment.tz("2018-10-10T13:00:00+11:00", "America/New_York"); |
Thanks, @simonhaenisch I've seen tz plugin, but I thought it helps to manage time zones, like converting from one to another . And it sounds weird to me to use it just to NOT touch time zone at all :)
Unfortunately, there is no a
That's ok, I don't care about the timezone. All I need is just to keep the coming date without changes.
This is what exactly happening. The timezone is a setting and the date saved with it as a timestamp. Since the backend API is under my control I'm able just to send reduced version of date, without time zone offset. I hope it helps. But, it's really interesting why the moment.js doesn't have something like that: moment(somDateTime).format({ formatWithDeviceTimezone: true }) or kind of :) Where Anyway, thanks, now I see the issue. |
You could try e.g. for a locale timezone in BST (UTC + 1) moment.parseZone("2018-10-10T13:00:00+11:00").format(); // "2018-10-10T13:00:00+11:00"
moment.parseZone("2018-10-10T13:00:00+11:00").local().format(); // "2018-10-10T03:00:00+01:00"
moment.parseZone("2018-10-10T13:00:00+11:00").utc().format(); // "2018-10-10T02:00:00Z" |
I know this is an old issue but let me just mention for posterity that it is mind blowing how framework can make weird decisions such as this one Why change timezone? The last thing you expect when parsing a date with time zone, is for it to get magically changed. When you parse |
Description of the Issue and Steps to Reproduce:
Say I received a date from backend in this format:
"2018-10-10T13:00:00+11:00"
What I expect to see in frontend after parsing and formatting:
10-10-2018 1.00 PM
What I got:
10-10-2018 5.00 AM
I don't care what my system time zone is. I don't want to see UTC time either. How can I achieve it?
Please include the values of all variables used.
See above.
Environment:
It doesn't matter, it shouldn't depend on the environment. That is the issue, btw, cause it depends!
The text was updated successfully, but these errors were encountered: