G
G
Gluck Virtualen2016-02-24 12:23:38
PHP
Gluck Virtualen, 2016-02-24 12:23:38

How to get the time from the database in someone else's timezone?

It seems that the task is simple, but for some reason the head refuses to think about it ... :)
The task is to track users from different timezones on the map. When clicking on the beacons, their local time should be shown, not mine.
The user arrives at a control point, say, in Khabarovsk at seven in the morning, presses the "Vasya was here" button. Its coordinates and its local time fly to the server (Date.now () from js).
On the mysql server, the storage format is datetime. Now done INSERT INTO tbl (date_upd) VALUES (FROM_UNIXTIME(:date_upd/1000) ). You can make any changes, the customer will not swear :)
An observer from Moscow sees a beacon on the map of Khabarovsk, clicks on it and gets - Vasya was here at 12 at night Moscow time.
Everything seems to be logical, but the observer needs to know what time Vasya was there according to Khabarovsk time. The observer is lazy and does not want to constantly recalculate the time, especially since "Vasya" is about two dozen, and they are all in different time zones.
How would you show him the correct time? Kick in the right direction, Great Gurus!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2016-02-26
@bingo347

Firstly, you can’t trust the client’s time, no one bothers me to manipulate the facts simply by setting the clock on my device
Secondly, passing time as an int timestamp is not a good idea, use a UTC string
Thirdly, moment.js will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question