JS/TS Convert unix timestamp to Time String

To Convert a unix timestamp to humman readable string, use new Date() with parameter * 1000,

convert unix timestamp to GMT String,

console.log(new Date(1665539594 * 1000).toGMTString());
//output 
Wed, 12 Oct 2022 01:53:14 GMT

To local string

console.log(new Date(1665539594 * 1000).toLocaleString());
//output
2022/10/12 09:53:14

To ISO string

console.log(new Date(1665539594 * 1000).toISOString());
//output
2022-10-12T01:53:14.000Z

To UTC string

console.log(new Date(1665539594 * 1000).toUTCString());
//output
Wed, 12 Oct 2022 01:53:14 GMT

Leave a Reply

Your email address will not be published. Required fields are marked *