Convert UTC date time to local date time

Amr Elgarhy picture Amr Elgarhy · Jun 29, 2011 · Viewed 712.4k times · Source

From the server I get a datetime variable in this format: 6/29/2011 4:52:48 PM and it is in UTC time. I want to convert it to the current user’s browser time using JavaScript.

How this can be done using JavaScript or jQuery?

Answer

digitalbath picture digitalbath · Jun 29, 2011

Append 'UTC' to the string before converting it to a date in javascript:

var date = new Date('6/29/2011 4:52:48 PM UTC');
date.toString() // "Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)"