D
D
Dima2312021-10-19 09:26:52
JavaScript
Dima231, 2021-10-19 09:26:52

Why does JSON.stringify somehow strangely convert an empty date?

Hello! In JavaScript, the JSON.stringify method confusingly converts an empty date. In the object itself, it looks like this: Mon Jan 01 0001 00:00:00. And in the string that is obtained after serialization, the date becomes like this: 0000-12-31T21:29:43. Those. the year was 0001 in the object, and 0000 in the Json string. As I understand it, it is because of this that Asp.net Core does not want to accept data from the client (when the model is filled in the controller parameters). Please tell me how to fix this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-10-19
@Rsa97

Deal with time zones as they were in 1 AD. Or keep everything in GMT, and recalculate only when withdrawing.

new Date('0001-01-01 00:00:00');
// Date Mon Jan 01 0001 00:00:00 GMT+0230 (Москва, стандартное время)

new Date('0001-01-01 00:00:00Z');
// Date Mon Jan 01 0001 02:30:17 GMT+0230 (Москва, стандартное время)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question