Answer the question
In order to leave comments, you need to log in
UNIX_TIMESTAMP taken from MySQL and converted to Date in JS gives weird result
Hello.
SELECT FROM_UNIXTIME(1342382400)
var date = new Date(1342382400*1000);
console.log(date)
Answer the question
In order to leave comments, you need to log in
Most likely yes, time zones, the difference is only one hour.
MySQL works in the time zone of the server, and JS in the time zone of the browser, that is, the client computer.
Apparently the server is running at GMT+0400
Yes, the difference in time zones is equal to one hour.
FROM_UNIXTIME() functions return values in the connection's current time zone
Store on the server in UTC, and on the client:
var timezoneDate = new Date();
var timezoneOffset = timezoneDate.getTimezoneOffset();
var date = new Date((1342382400 - (timezoneOffset * 60)) * 1000);
console log(date);
From the timestamp in seconds, subtract the timezone shift (in minutes * 60) in seconds, then multiply by the mower and make happiness :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question