Created
May 29, 2014 16:54
-
-
Save mdp/e733fff433ccbe3d41cd to your computer and use it in GitHub Desktop.
Local time in javascript
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
function localTime(offset) { | |
var d = new Date(); | |
var utc = d.getTime() + (d.getTimezoneOffset() * 60000); | |
return new Date(utc + (3600000*offset)); | |
} | |
localTime(5.5); | |
localTime(-8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment