Method 1: Using toUTCString()
The toUTCString() method is used to represent the Date object as a string in the UTC format.
In this example:
- The date.toUTCString() gives you the date and time in UTC.
- The date.toLocaleString() gives you the date and time in the local timezone of the system where the code is running.
Method 2: Getting individual hours, minutes, and seconds
Using the Date() function, we can then turn this value into a Date object.
For a neat display, numbers are transformed into strings and padded with zeros, if needed, using toString() and padStart(). These components are combined with colons to represent the complete time derived from the UNIX timestamp.