You can use the Date()
constructor to get the current date and time in javascript. Then you can use the getFullYear()
, getMonth()
, and getDate()
methods to extract the year, month, and date respectively. Here's how you can get the current time in ddmmyy
format:
384 chars8 lines
Note that getMonth()
returns a zero-based index, hence the need to add 1 to the month and the use of padStart()
to add a leading zero.
gistlibby LogSnag