How to work with date?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
8 views
On the website datepicker, with which users select a date. I need only date, Without time. Selected the date I store in the database. In the database plain text field. The date is stored in format "2019-01-25T12:04:00.000 Z".
Now, to display this date, I use "let d = new Date(savedDate)".
And then there are bugs. For example (very rarely) there are cases when datepicker selected, for example, the number 24, but using new Date (), and .getDate() is displayed 23. And the amazing thing is that in the database, too, is 23!
I assume that the case in our time zones. The problem is that you cannot get a naked date, without the time and everything else, only include month and year. The library returns the same format.
How to work with date?
by | 8 views

2 Answers

0 like 0 dislike
If it is MySQL database, it is better to save time relative to the time zone of the server, it does not need the front to transfer the date, use the date type TIMESTAMP (by default, the SQL function NOW() ). The client, the date will not be cached ( new Date(server timestamp * 1000) ) relative to its time zone.
If you still need to pass the server date, send date.toUTCString() UTC or, as said Emil Revencu, to take new Date().getTime() / 1000 ( new Date().getTime() is in milliseconds )
by
0 like 0 dislike
Try to save the TIMESTAMP (as an example new Date().getTime())
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Aug 13, 2019 by kirill-93
0 like 0 dislike
2 answers
asked Jul 9, 2019 by kirill-93
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
27,920 users