Skip to content

Instantly share code, notes, and snippets.

@macloo
Last active December 17, 2015 02:29
Show Gist options
  • Save macloo/41bb647efebe9f88bfa2 to your computer and use it in GitHub Desktop.
Save macloo/41bb647efebe9f88bfa2 to your computer and use it in GitHub Desktop.
JavaScript for date string
// produce a data string in this format: 2015-12-17 01:31:39
function getDate() {
var date = new Date();
timestamp = date.getUTCFullYear() + '-' +
('00' + (date.getUTCMonth() + 1)).slice(-2) + '-' +
('00' + date.getUTCDate()).slice(-2) + ' ' +
('00' + date.getUTCHours()).slice(-2) + ':' +
('00' + date.getUTCMinutes()).slice(-2) + ':' +
('00' + date.getUTCSeconds()).slice(-2);
return timestamp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment