Created
June 3, 2020 19:29
-
-
Save VincentVToscano/07217a65f82387c3b1ace1f3fc5beb01 to your computer and use it in GitHub Desktop.
Get User’s local timestamp that can be utilized client or for inclusion on strings to be sent to backend.
This file contains 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
/** | |
* getUsersLocalTimestamp --- Get User’s local timestamp for inclusion on strings sent to backend. | |
* @returns {string} "2020-06-03 @ 12:12:25" | |
* @usage getUsersLocalTimestamp() | |
*/ | |
function getUsersLocalTimestamp() { | |
let date = new Date(); | |
let yyyy = date.getFullYear().toString(); | |
let mm = (date.getMonth() + 1).toString(); | |
let dd = date.getDate().toString(); | |
return yyyy + '-' + (mm[1] ? mm : "0" + mm[0]) + '-' + (dd[1] ? dd : "0" + dd[0]) + ' @ ' + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment