Created
March 8, 2021 21:58
-
-
Save Fernando74lr/058a7972f9acb1cf036ffece7dfe0229 to your computer and use it in GitHub Desktop.
Get current datetime
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
// Get current date | |
function getCurrentDate() { | |
let today = new Date(); | |
let day = String(today.getDate()).padStart(2, '0'); | |
let month = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! | |
let year = today.getFullYear(); | |
return `${day.length == 1 ? '0' + day : day}/${month.length == 1 ? '0' + month : month}/${year}`; | |
} | |
// Get current time | |
function getCurrentTime() { | |
let date = new Date(); | |
return date.toString().split(' ')[4]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment