In this article let us take a look at how you can utilise this function to perform the conversions.
Converting Milliseconds to Date
To Convert milliseconds to date you simply need to use “var” or “const” to declare a variable which has the value of the milliseconds stored in it.
Once the millisecond integer is stored into a variable, use the “Date()” constructor to convert the milliseconds into date and then store it into the new variable “checkDate”.
The complete code snippet along with the output is given below for reference:
As shown in this snippet, you will get an output of the date corresponding to the milliseconds that you input into the variable.
Conversion from Date to various String Formats?
Once you have your date in a variable, you can use various string methods to display the date in any format that you prefer. Some common formats are shown below:
The following method will return the string in the locale format that your system is using:
The use of this method will return the string with only the Date and not the time:
The following method will display only the time out of the Date conversion: