Skip to content

Instantly share code, notes, and snippets.

@matthewdfuller
Last active November 6, 2015 12:46
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 matthewdfuller/69eb1aa1e57d4b24254d to your computer and use it in GitHub Desktop.
Save matthewdfuller/69eb1aa1e57d4b24254d to your computer and use it in GitHub Desktop.
Formats a JavaScript date with leading zeros
var date = new Date();
var dateString = date.getFullYear() + '/' + ('0' + (date.getMonth()+1)).slice(-2) + '/' + ('0' + date.getDate()).slice(-2) + ' ' + ('0' + date.getHours()).slice(-2) + ':' + ('0' + date.getMinutes()).slice(-2) + ':' + ('0' + date.getSeconds()).slice(-2);
@Chunlin-Li
Copy link

good idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment