Skip to content

Instantly share code, notes, and snippets.

@Fernando74lr
Created March 8, 2021 21:58
Show Gist options
  • Save Fernando74lr/058a7972f9acb1cf036ffece7dfe0229 to your computer and use it in GitHub Desktop.
Save Fernando74lr/058a7972f9acb1cf036ffece7dfe0229 to your computer and use it in GitHub Desktop.
Get current datetime
// 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