Home > Back-end >  How to get date and time
How to get date and time

Time:04-12

document.getElementById('sunrise').innerHTML = (new Date(d.sys.sunrise * 1000)).toLocaleDateString()

The above code display date, how can I get date and time?

CodePudding user response:

you can just use

.toLocaleTimeString()

the same way it will display also the time

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString

CodePudding user response:

You can just do this :

 new Date().toLocaleString())

You have now the date and the time.

documentation here : toLocaleString() doc

CodePudding user response:

You can use .toTimeString() to get the time in string.

  • Related