Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store `new Date ()` in JSON object

I have the following field validator object:

{ type:'date', 'min':new Date() }

I was hoping that I could store new Date() as an expression in JSON and it would be executed when it's parsed

like image 587
stackoverfloweth Avatar asked Sep 18 '25 23:09

stackoverfloweth


1 Answers

save the timestamp:

{ type:'date', 'min':(new Date()).getTime() }

then you read it back:

var result = JSON.parse('{ "type":"date", "min":1234567 }');
result.date = new Date(result.min);

Note: the server you use to serialize it and the server you use to deserialize it has to run in the same timezone

like image 86
Gavriel Avatar answered Sep 21 '25 11:09

Gavriel