Tuesday, June 28, 2016

JavaScript - Convert ISO Date to Browser's/ local time zone

JavaScript - Convert ISO Date to Browser's/ local time zone

date.js is pretty handy when we need to manipulate Dates in javascript.

Following two lines of code shows how we can convert an ISO date in UTC to users local time.

Include date.js in your page and create a new Date object passing the ISO date string.
date.js will take care of creating a date object in local timezone using the date object you passed.

Sample Javascript:

var dateTime = new Date("2016-06-28T01:40:12.000Z");

var localTimeFormat = dateTime.toString("MM/dd/yyyy hh:mm tt");

alert(localTimeFormat);


References:



No comments:

Post a Comment