Created
May 21, 2020 14:35
-
-
Save kishorpawar/dbf20b45c0f4836a6e46f5ef7095cbe8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function converts UTC date string to browser's time zone. | |
// and returns locale formatted date. | |
function toUserTimezone(utcDate){ | |
timezoneOffset = new Date().getTimezoneOffset() * -1; | |
tojsDateObj = new Date(utcDate); | |
convertedDate = new Date(tojsDateObj.getTime() + (timezoneOffset * 60000)); | |
return convertedDate.toLocaleString(); | |
} | |
// this function coverts browser's zone specific dates to UTC timezone. | |
function toUTCTimezone(zoneDate){ | |
timezoneOffset = new Date().getTimezoneOffset() * -1; | |
tojsDateObj = new Date(zoneDate); | |
convertedDate = new Date(tojsDateObj.getTime() - (timezoneOffset * 60000)); | |
return convertedDate | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment