I need to create a Timestamp like below. I have tried lots of ways , but couldn't get this format.
How can I create a current time and date in this Timestamp format in JavaScript ??
2018-08-20T04:19:50.670Z
I need to create a Timestamp like below. I have tried lots of ways , but couldn't get this format.
How can I create a current time and date in this Timestamp format in JavaScript ??
2018-08-20T04:19:50.670Z
Try this
console.log(new Date().toISOString());
You can create a Timestamp like 2018-08-20T04:19:50.670Z
using
console.log(new Date().toISOString());
Or,
console.log(new Date());
But note that in chrome
console.log(new Date().toISOString());
will return timestamp in this format:
`2018-08-20T06:19:24.386Z`
but
console.log(new Date());
will return timestamp in this format: Mon Aug 20 2018 11:50:23 GMT+0530 (India Standard Time)
But in Mozilla, both yeilds same result.
If you use .toISOString()
with new Date()
, then it will return a string
of the timestamp, otherwise it will return a Date
object. This is the only difference in using .toISOString()
. So, its depends on you what do you want???