Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Datetime in React

🎈 🎈 🎈
+1

    import React from 'react';

    function UnixToDate() {
        const unixTimestamp = 1624814363;
        const date = new Date(unixTimestamp * 1000);
    
        // Format the date
        const formattedDate = date.toLocaleString();
    
        return (
        <div>
            <p>Converted Date: {formattedDate}</p>
        </div>
        );
    }
    
    export default UnixToDate;            
        

Output:
Converted Date: 2021-06-27 17:19:23
Example only. There may be multiple ways to perform this operation.

Code Explanation

For this React snippet we use the Unix timestamp value of 1624814363 which corresponds to 2021-06-27 17:19:23.
It is multiplied by 1000 to convert it from seconds to milliseconds, which is then passed to the Date constructor. Then, the toLocaleString() method formats the date into a readable format based on the user's locale, and the formatted date is rendered in a React component.



Other useful React date functions

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 a formatted date string like 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