Reputation: 2599
When i try to serialize a javascript date object to json, with JSON.stringify(), i get something like
"2014-10-27T15:00:00.000Z"
What is the T15 after 27 ? Is there a way to get always T00 ?
Upvotes: 1
Views: 234
Reputation: 4124
JSON.stringify uses toJSON javascript Date method. It returns an ISO-formatted date string for the UTC time zone (denoted by the suffix Z). So, if you want to get 00 hours, you have to set it by setUTCHours
:
var date = new Date();
date.setUTCHours(0,0,0,0);
Check this link to see a working example.
Hope it's useful!
Upvotes: 0
Reputation: 100175
T
appears in that string to indicate the beginning of time element, so T15:00:00
, means 15 hours, 0 minutes and 0 seconds, so its THH:mm:ss
If you want to set hours, minutes and seconds to 0, then with javascript you could use setHours(), as
var d = new Date();
d.setHours(0,0,0,0);
It will set time to 00:00:00.000
of your timezone
Upvotes: 2