Skip to content

Instantly share code, notes, and snippets.

@xbalaji
Last active December 31, 2018 04:06
Show Gist options
  • Save xbalaji/f56d5cc8a10b516695c0e29394fa5ecc to your computer and use it in GitHub Desktop.
Save xbalaji/f56d5cc8a10b516695c0e29394fa5ecc to your computer and use it in GitHub Desktop.
javascript to zero pad dates
<script>
var d = new Date();
var mm = (d.getMonth() + 1).toString().padStart(2, "0");
var dd = (d.getDate()).toString().padStart(2, "0");
var yy = ((d.getFullYear() %100).toString()).padStart(2, "0");
var date_str = '' + mm + '-' + dd + '-' + yy;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment