Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Datetime to Unix timestamp in JavaScript

🎈 🎈 🎈
+1

    const date = new Date('1990-07-15T10:17:40Z');
    const unixTimestamp = Math.floor(date.getTime() / 1000);
    console.log("Unix Timestamp: " + unixTimestamp);            
        

Output:
Unix Timestamp = 648037060
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this JavaScript code, a Date object with the specific date and time ('1990-07-15T10:17:40Z') is created.
The getTime() method is then called on this Date object to get the number of milliseconds since the Unix epoch. Since Unix timestamps are conventionally expressed in seconds, the millisecond value is divided by 1000 and rounded down using Math.floor() to produce the final Unix timestamp.
This approach allows you to convert any date and time in JavaScript into the corresponding Unix timestamp, which represents the total number of seconds since the Unix epoch.


Other useful JavaScript date functions

Function Description Example
Date() Creates a new date object representing the current date and time. new Date() returns Wed Aug 28 2024 12:34:56 GMT+0000 (Coordinated Universal Time)
Date.now() Returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC. Date.now() returns 1693227296789
Date.parse() Parses a date string and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. Date.parse("2024-08-28T12:34:56Z") returns 1727420096000
getFullYear() Returns the year of the specified date according to local time. new Date().getFullYear() returns 2024
getMonth() Returns the month (0-11) of the specified date according to local time. new Date().getMonth() returns 7 for August (0-indexed)
getDate() Returns the day of the month (1-31) for the specified date according to local time. new Date().getDate() returns 28
getDay() Returns the day of the week (0-6) for the specified date according to local time. new Date().getDay() returns 3 for Wednesday (0 = Sunday)
getHours() Returns the hour (0-23) of the specified date according to local time. new Date().getHours() returns 12
getMinutes() Returns the minutes (0-59) of the specified date according to local time. new Date().getMinutes() returns 34
getSeconds() Returns the seconds (0-59) of the specified date according to local time. new Date().getSeconds() returns 56
getTime() Returns the number of milliseconds since January 1, 1970, 00:00:00 UTC for the specified date. new Date().getTime() returns 1693227296789
toISOString() Returns the date as a string in ISO format (YYYY-MM-DDTHH:mm:ss.sssZ). new Date().toISOString() returns 2024-08-28T12:34:56.789Z
toLocaleDateString() Returns the date portion of a Date object as a string, using locale conventions. new Date().toLocaleDateString() returns 08/28/2024 in the US format
toLocaleTimeString() Returns the time portion of a Date object as a string, using locale conventions. new Date().toLocaleTimeString() returns 12:34:56 PM
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