Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  3] [ 2]  / answers: 1 / hits: 27094  / 9 Years ago, wed, july 1, 2015, 12:00:00

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,
category:UI,
severity:MAJOR,
source:BILLING,
status:ASSIGNED
}
]


we are able to get CreationTime into a String variable but unable to convert to UTC. Any idea to convert this?


More From » datetime

 Answers
2

Using toUTCString():



var toUTC = new Date(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.


[#65965] Monday, June 29, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dezmondhumbertob

Total Points: 79
Total Questions: 112
Total Answers: 107

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
;