Skip to content

Instantly share code, notes, and snippets.

@gokusenz
Created June 5, 2020 18:29
Show Gist options
  • Save gokusenz/5181c7a79113ede8ebc48006a9061ccc to your computer and use it in GitHub Desktop.
Save gokusenz/5181c7a79113ede8ebc48006a9061ccc to your computer and use it in GitHub Desktop.
JS Timestamp
var now = new Date();
var nowUTC = now.getTime() + now.getTimezoneOffset() * 60 * 1000;
var utc_timestamp = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(),
now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds());
document.write("Correct UTC timestamp " + now.getTime());
document.write("<br/>");
document.write("Incorect UTC timestamp " + utc_timestamp);
document.write("<br/>");
document.write("Incorect UTC timestamp " + nowUTC);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment