Last active
October 25, 2017 03:28
-
-
Save mrksdiehl/11b2a30563b16c908443d48bc05735d0 to your computer and use it in GitHub Desktop.
Get the timestamp set the timezone and return a string with all glued together
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
| var timezoneOffset = 8; | |
| var d = new Date(); | |
| var utc = d.getTime() + (d.getTimezoneOffset() * 60000); | |
| var timestamp = new Date(utc + (3600000*timezoneOffset)); | |
| var time_string = timestamp.getFullYear().toString() | |
| time_string += timestamp.getMonth() < 10 ? '0' + timestamp.getMonth().toString() : timestamp.getMonth().toString(); | |
| time_string += timestamp.getDate() < 10 ? '0' + timestamp.getDate().toString() : timestamp.getDate().toString(); | |
| time_string += timestamp.getHours() < 10 ? '0' + timestamp.getHours().toString() : timestamp.getHours().toString(); | |
| time_string += timestamp.getMinutes() < 10 ? '0' + timestamp.getMinutes().toString() : timestamp.getMinutes().toString(); | |
| time_string += timestamp.getSeconds() < 10 ? '0' + timestamp.getSeconds().toString() : timestamp.getSeconds().toString(); | |
| time_string += (function(timestamp){ | |
| if(timestamp.getMilliseconds() < 10 ){ | |
| return '000' + timestamp.getMilliseconds().toString() | |
| } | |
| else if( timestamp.getMilliseconds() >= 10 && timestamp.getMilliseconds() < 100 ){ | |
| return '00' + timestamp.getMilliseconds().toString() | |
| } | |
| else if( timestamp.getMilliseconds() >= 100 && timestamp.getMilliseconds() < 1000 ){ | |
| return '0' + timestamp.getMilliseconds().toString() | |
| } | |
| else { | |
| return timestamp.getMilliseconds().toString() | |
| } | |
| }(timestamp)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment