Formatting a date in javascript till the millisecond
Use 'S' for milliseconds formatting:
"dd/MM/yyyy HH:mm:ss:SSS"
It's indicated by an f:
"dd/MM/yyyy HH:mm:ss fff"
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.