Created
August 6, 2022 16:55
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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