Skip to content

Instantly share code, notes, and snippets.

@deostroll
Forked from DevelopKim/dateformatting
Last active July 21, 2021 11:48
Show Gist options
  • Save deostroll/5861be7974bb76a0f62bcf75ce3d8e9c to your computer and use it in GitHub Desktop.
Save deostroll/5861be7974bb76a0f62bcf75ce3d8e9c to your computer and use it in GitHub Desktop.
javascript date formatting
var today = new Date();
function fmtDate(today) {
return `${today.getFullYear()}${('0' + (today.getMonth() + 1)).slice(-2)}${('0' + today.getDate()).slice(-2)}-${('0' + today.getHours()).slice(-2)}_${('0' + today.getMinutes()).slice(-2)}_${('0' + today.getSeconds()).slice(-2)}`;
}
fmtDate(today);
//ex . Wed Aug 28 2013 17:50:28 GMT+0900 (KST) -> "20130828_17-50-28"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment