Amr Elgarhy Amr Elgarhy - 3 years ago 139
jQuery Question

Convert UTC date time to local date time

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 Source

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)"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download