Skip to content

Instantly share code, notes, and snippets.

@DavidEredics
Created October 14, 2018 15:41
Show Gist options
  • Save DavidEredics/c10fff5e6a4f6fc8867e042533aee1c6 to your computer and use it in GitHub Desktop.
Save DavidEredics/c10fff5e6a4f6fc8867e042533aee1c6 to your computer and use it in GitHub Desktop.
JavaScript UTC DateTime function
function DateTime(){
var date = new Date();
var year = date.getUTCFullYear();
var month = date.getUTCMonth() + 1;
month = (month < 10 ? "0" : "") + month;
var day = date.getUTCDate();
day = (day < 10 ? "0" : "") + day;
var hour = date.getUTCHours();
hour = (hour < 10 ? "0" : "") + hour;
var minutes = date.getUTCMinutes();
minutes = (minutes < 10 ? "0" : "") + minutes;
var seconds = date.getUTCSeconds();
seconds = (seconds < 10 ? "0" : "") + seconds;
return year + "/" + month + "/" + day + "-" + hour + ":" + minutes + ":" + seconds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment