How to convert result from JavaScript Date.now() to yyyy/MM/dd hh:mm:ss ffff format?

Sometimes, we want to convert result from JavaScript Date.now() to yyyy/MM/dd hh:mm:ss ffff format.

In this article, we’ll look at how to convert result from JavaScript Date.now() to yyyy/MM/dd hh:mm:ss ffff format.

How to convert result from JavaScript Date.now() to yyyy/MM/dd hh:mm:ss ffff format?

To convert result from JavaScript Date.now() to yyyy/MM/dd hh:mm:ss ffff format, we can use moment.js.

For instance, we write:

const d = moment().format('YYYY/MM/D hh:mm:ss SSS')
console.log(d)

We get the current date time with moment().

Then we call format with 'YYYY/MM/D hh:mm:ss SSS' to return a string of the current date time in yyyy/MM/dd hh:mm:ss ffff format.

Therefore d is '2022/01/7 04:58:24 671'.

Conclusion

To convert result from JavaScript Date.now() to yyyy/MM/dd hh:mm:ss ffff format, we can use moment.js.