Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Convert Date To UTC [duplicate]

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.

like image 326
JIbber4568 Avatar asked Oct 11 '12 09:10

JIbber4568


People also ask

How do you convert a JavaScript date to UTC?

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.

Does JavaScript date use UTC?

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.

How do I convert a date to a different time zone?

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.

How do you convert UTC to moments in dates?

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();


1 Answers

Check this out: How do I format a Microsoft JSON date?

var date = new Date(parseInt(jsonDate.substr(6)));
like image 139
arpad Avatar answered Oct 04 '22 19:10

arpad