Skip to content Skip to sidebar Skip to footer

Convert Datetime String To Utc In Javascript

How can we convert datetime string to UTC in javascript. We are getting following JSON from REST service [ { 'CreationTime':'June 2, 2015 8:04:53 PM IST', 'categ

Solution 1:

Using toUTCString():

var toUTC = newDate("June 2, 2015 8:04:53").toUTCString()

In Javascript you can use this method to convert a date from a Date() object, but not from a IST string. So you need format this string to a Date() object , then you can convert it to UTC. In this topic says what I mean.

Note If you try June 2, 2015 8:04:53 PM IST JavasScript take it as invalid date, for that you have to use .replace() function to remove the IST part of the string.

Post a Comment for "Convert Datetime String To Utc In Javascript"