Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created August 6, 2022 16:55
Show Gist options
  • Save hieptl/071a2bdb1fc91df6613f8d3a63fdef3f to your computer and use it in GitHub Desktop.
Save hieptl/071a2bdb1fc91df6613f8d3a63fdef3f to your computer and use it in GitHub Desktop.
How to Get the Current Date in Javascript - Format Date & Time(YYYY-MM-DD HH:MM:SS)
const currentDate = new Date();
const yyyyMMDDDate =
currentDate.getFullYear() +
"-" +
(currentDate.getMonth() + 1) +
"-" +
currentDate.getDate();
const hhMMSSTime =
currentDate.getHours() +
":" +
currentDate.getMinutes() +
":" +
currentDate.getSeconds();
console.log(`${yyyyMMDDDate} ${hhMMSSTime}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment