Created
December 18, 2013 07:00
-
-
Save thebagg/8018352 to your computer and use it in GitHub Desktop.
Get todays date in DD/MM/YYYY format.
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
var today = new Date(); | |
var dd = today.getDate(); | |
var mm = today.getMonth()+1; //January is 0! | |
var yyyy = today.getFullYear(); | |
if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} today = dd+'/'+mm+'/'+yyyy; | |
document.write(today); |
// using slice
let date = new Date()
let day = `0${date.getDate()}`.slice(-2); //("0"+date.getDate()).slice(-2);
let month = `0${date.getMonth()+1}`.slice(-2);
let year = date.getFullYear();
console.log(${day}-${month}-${year})
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.