B
B
Belavor2019-09-24 17:46:58
PHP
Belavor, 2019-09-24 17:46:58

How to change time zone from server to user?

How to change time zone from server to user?
this function gets the time from the server i.e. GMT+00:00 but I need gmt+0600
const curTime = new Date();

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lander, 2018-05-16
@usdglander

I'm certainly no expert, but isn't window.top.location...?

S
SagePtr, 2019-09-24
@Belavor

Moment.js supports timezones.
Either pass the time in the form of unix seconds, and on the client side already format and display in the local time zone.

S
Sergey Melodin, 2019-09-24
@melodyn

You can use moment, as the author of the answer above mentioned, but not everything is smooth there either. Here you can see an example of usage: https://repl.it/@Melodyn/momentJS
In general, working with UTC offset in Moment is not much different from the same in Date. Just use the date in ISO format and append the tail:

new Date('2019-09-24T12:00:00+0000') // время по UTC
new Date('2019-09-24T12:00:00+0300') // время по Москве
new Date('2019-09-24T12:00:00+0300') // время по Москве
new Date('2019-09-24T12:00:00+0600') // время по вашем региону

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question