H
H
Hazrat Hajikerimov2018-05-24 16:52:55
JavaScript
Hazrat Hajikerimov, 2018-05-24 16:52:55

How to fix time in javascript if user in system has wrong date?

Hi friends, I use the moment library to display the last user actions using the method moment(date).fromNow(), it looks like this: a
minute ago
5 minutes ago
And if the user does not have the correct time, then moment can display the following text: in
14 minutes
in 19 minutes
then fix the local time in the browser?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Wolf, 2018-05-24
@hazratgs

Obviously, either transmit the already processed time from the server (that is, in text, for example), or transmit the page opening time from the server, on the client, when loading, count the difference between the client and the server and compensate for this difference with each time output.
In moment, you can even override the current time and simply make it equal to the server time.

T
TerNik, 2018-05-24
@TerNik

Do you datetake into account the user's time zone?

var testDateUtc = moment.utc("2015-01-30 10:00:00");
var localDate = moment(testDateUtc).local();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question