Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Unix Timestamp to Datetime in TypeScript

How to convert Unix timestamp to Datetime in TypeScript

🎈 🎈 🎈
+1

    const unixTimestamp: number = 1222562910;
    const date: Date = new Date(unixTimestamp * 1000); // Convert to milliseconds
    const formattedDate: string = date.toLocaleString();
    
    console.log(`Converted Date: ${formattedDate}`);            
        

Output:
Converted Date: 2008-09-28 00:48:30
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this example of Unix timestamp to date conversion in TypeScript, 1222562910 (Unix timestamp for 2008-09-28 00:48:30) is converted into a Date object by multiplying it by 1000 (to convert from seconds to milliseconds).
The toLocaleString() method formats the Date object into a human-readable string based on the user's locale, and the result is printed using console.log.


Other useful TypeScript date functions (JavaScript Date API)

Function Description Example
new Date() Creates a new date object representing a specific date and time, or the current date and time if no argument is provided. new Date(1514764800 * 1000) returns Mon Jan 01 2018 00:00:00 GMT+0000
getTime() Returns the number of milliseconds since January 1, 1970 for the given date. date.getTime() returns 1531657845000 for 2018-07-15 12:30:45
toLocaleString() Returns a string with a language-sensitive representation of the date. date.toLocaleString() returns 1/1/2018, 12:00:00 AM
toISOString() Converts a date object to an ISO 8601 string in UTC. date.toISOString() returns 2018-01-01T00:00:00.000Z
toUTCString() Converts a date to a string in UTC format. date.toUTCString() returns Mon, 01 Jan 2018 00:00:00 GMT
setFullYear() Sets the year for a date object. date.setFullYear(2020) sets the year to 2020.
getFullYear() Gets the year from a date object. date.getFullYear() returns 2018.
setMonth() Sets the month for a date object (0 for January). date.setMonth(0) sets the month to January.
getMonth() Gets the month from a date object (0 for January). date.getMonth() returns 0 for January.
getDate() Gets the day of the month from a date object. date.getDate() returns 1.
setHours() Sets the hours for a date object. date.setHours(12) sets the hours to 12.
getHours() Gets the hours from a date object. date.getHours() returns 0 (for midnight).
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder