Skip to content

Instantly share code, notes, and snippets.

@VincentVToscano
Created June 3, 2020 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VincentVToscano/07217a65f82387c3b1ace1f3fc5beb01 to your computer and use it in GitHub Desktop.
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.
/**
* 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