Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var serverDate = '2014-02-24 04:52:48.050000'; // EST
- function convertServerDateToLocal(dateInput) {
- // EST - UTC offset: 5 hours
- var offset = 5.0,
- /*
- - calculate the difference between the server date and UTC
- - the value returned by the getTime method is the number of milliseconds since 1 January 1970 00:00:00 UTC.
- - the time-zone offset is the difference, in minutes, between UTC and local time
- - 60000 milliseconds = 60 seconds = 1 minute
- */
- serverDate = new Date(dateInput),
- utc = serverDate.getTime() - (serverDate.getTimezoneOffset() * 60000),
- /*
- - apply the offset between UTC and EST (5 hours)
- - 3600000 milliseconds = 3600 seconds = 60 minutes = 1 hour
- */
- clientDate = new Date(utc + (3600000 * offset));
- return clientDate.toLocaleString();
- }
- console.log(convertServerDateToLocal(serverDate));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement