You can use the fromUnixTime function from the date-fns library in JavaScript to convert a Unix timestamp to a JavaScript Date object. Here is an example:
235 chars7 lines
In the example above, we import the fromUnixTime function from the date-fns package. We then create a variable called unixTimestamp that contains the Unix timestamp that we want to convert. Finally, we use the fromUnixTime function to convert the timestamp to a Date object and store the result in a variable called date. We then log the date variable to the console.
Note that the fromUnixTime function assumes that the Unix timestamp is expressed in seconds. If your timestamp is expressed in milliseconds, you will need to divide it by 1000 before passing it to the function.
gistlibby LogSnag