Possible Duplicate:
How to format a JSON date?
I have a JSON that contains some dates that I need to be in a UTC format.
At present if I alert the dates out they are in the following format:
/Date(1329314400000)/
I am trying to loop round the JSON but am unsure on how to convert the above date format to UTC.
If anyone has any advice I would greatly appreciate it.
To convert a JavaScript date object to a UTC string, you can use the toUTCString() method of the Date object. The toUTCString() method converts a date to a string, using the universal time zone. Alternatively, you could also use the Date. UTC() method to create a new Date object directly in UTC time zone.
The Date. UTC() method in JavaScript is used to return the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time. The UTC() method differs from the Date constructor in two ways: Date.
To convert a date to another time zone: Use the toLocaleString() method to get a string that represents the date according to the provided time zone. Pass the result to the Date() constructor. The returned Date object will have its date and time set according to the provided time zone.
To convert date to UTC using moment. js and JavaScript, we can use the moment's utc method. const utcStart = new moment("2022-06-24T09:00", "YYYY-MM-DDTHH:mm"). utc();
Check this out: How do I format a Microsoft JSON date?
var date = new Date(parseInt(jsonDate.substr(6)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With