javascript convert utc to local time 1

javascript convert utc to local time

var UTCDate = '6/29/2011 4:52:48 PM';
var localDate = new Date(UTCDate + ' UTC');

Here is what the above code is Doing:
1. We create a string that represents a date in UTC format.
2. We create a new Date object, passing in the UTC date string.
3. We print out the value of the Date object.

The output of the above code is:

Fri Jun 29 2011 12:52:48 GMT-0400 (Eastern Daylight Time)

Notice that the date is automatically converted to the browser’s time zone and date format.

Similar Posts