Formatting a date in javascript till the millisecond

If you are using the native Date javascript object, you can simply use .toISOString method to get a formatted string with milliseconds:

const date = new Date();
const dateString = date.toISOString(); // "2020-01-06T19:57:12.146Z"

Note that using .toString won’t give you milliseconds precision.

Leave a Comment