var seconds = new Date().getTime() / 1000;

....will give you the seconds since midnight, 1 Jan 1970

Reference

Answer from sje397 on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › now
Date.now() - JavaScript | MDN
// This example takes 2 seconds to run const start = Date.now(); console.log("starting timer..."); // Expected output: "starting timer..." setTimeout(() => { const ms = Date.now() - start; console.log(`seconds elapsed = ${Math.floor(ms / 1000)}`); // Expected output: "seconds elapsed = 2" }, ...
🌐
W3Schools
w3schools.com › jsreF › jsref_getseconds.asp
JavaScript Date getSeconds() Method
getSeconds() returns the seconds (0 to 59) of a date. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make ...
🌐
QuickRef.ME
quickref.me › home › how to get the current timestamp in seconds in javascript - quickref.me
How to get the current timestamp in seconds in JavaScript - QuickRef.ME
In this Article we will go through how to get the current timestamp in seconds only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-the-current-date-and-time-in-seconds
How to get the current date and time in seconds ? - GeeksforGeeks
July 11, 2025 - We will perform it in 2 ways: ... The Date.now() method returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC. This is known as the epoch time. It may be used for timestamping as an order of events could easily be checked ...
🌐
Medium
medium.com › @python-javascript-php-html-css › a-guide-to-obtaining-a-timestamp-in-javascript-04a81f4e5b9c
A Guide to Obtaining a Timestamp in JavaScript
September 22, 2024 - This guide will walk you through the process of obtaining a timestamp in JavaScript, which can be useful for various applications such as logging events, scheduling, or simply keeping track of time.
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-date-exercise-17.php
JavaScript: Convert a Unix timestamp to time - w3resource
July 17, 2025 - The code defines a JavaScript function named "Unix_timestamp()" with one parameter 't', which represents a UNIX timestamp (number of seconds since January 1, 1970). ... It creates a new Date object named 'dt' by converting the UNIX timestamp ...
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › get-current-date-time-in-seconds-javascript
Get current date/time in seconds - JavaScript?
January 27, 2025 - Then, multiply the hours to 3600 and minutes to 60; rest you can see below − ... <html> <head> <title>JavaScript Get Seconds</title> </head> <body> <script> var dt = new Date(); var sec = dt.getSeconds(); document.write("Seconds: " + sec); var min = dt.getMinutes(); document.write("<br>Minutes: ...
🌐
Toptal
toptal.com › developers › software › definitive-guide-to-datetime-manipulation
How to get the Timestamp And Date in Javascript: JS DateTime | Toptal®
December 2, 2020 - If you instead want to get the current timestamp in JavaScript, you can create a new Date object and use the getTime() method.
🌐
Stack Abuse
stackabuse.com › bytes › how-to-convert-a-date-to-timestamp-in-javascript
How to Convert a Date to Timestamp in JavaScript
October 4, 2023 - In this Byte, we'll explore how to convert a date or date string to a timestamp in JavaScript. But why do we need to convert a date or date string to a timestamp in the first place? Timestamps are a more universal way of storing date and time information. They represent the number of seconds (or ...
🌐
Futurestud.io
futurestud.io › tutorials › how-to-get-a-unix-timestamp-in-javascript-or-node-js
How to Get a UNIX Timestamp in JavaScript or Node.js
June 23, 2022 - JavaScript’s global Date object comes with methods to interact with dates and times. The Date.now() function returns the current timestamp in milliseconds. These milliseconds are counted from the UNIX epoch. That means you need to convert these milliseconds to seconds and you’re receiving the UNIX time:
🌐
LabEx
labex.io › tutorials › unix-timestamp-from-date-28683
Get Unix Timestamp from Date in JavaScript | LabEx
You can use the following steps to get the Unix timestamp from a Date object in JavaScript: Use Date.prototype.getTime() to get the timestamp in milliseconds. Divide the timestamp by 1000 to get the timestamp in seconds. Use Math.floor() to ...
🌐
Moment.js
momentjs.com › docs
Moment.js | Docs
This is implemented as moment(timestamp * 1000), so partial seconds in the input timestamp are included. ... Note: Despite Unix timestamps being UTC-based, this function creates a moment object in local mode. If you need UTC, then subsequently call .utc(), as in: ... You can create a Moment ...
🌐
Coderwall
coderwall.com › p › rbfl6g › how-to-get-the-correct-unix-timestamp-from-any-date-in-javascript
How to get the correct Unix Timestamp from any Date in JavaScript (Example)
June 26, 2023 - Unfortunately, there's a small ... Date.getTime(): A Unix timestamp is defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970....
🌐
Readthedocs
momentjscom.readthedocs.io › en › latest › moment › 01-parsing › 08-unix-timestamp
Unix Timestamp (seconds) - momentjs.com
This is implemented as moment(timestamp * 1000), so partial seconds in the input timestamp are included.
🌐
ui.dev
ui.dev › get-current-timestamp-javascript
How to get the current timestamp in JavaScript
The UNIX timestamp is defined as the number of seconds since January 1, 1970 UTC. In JavaScript, in order to get the current timestamp, you can use Date.now().
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
Note that unlike many other systems, timestamps in JavaScript are in milliseconds, not in seconds.
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › date › date to unix timestamp
Convert between a JavaScript Date object and a Unix timestamp - 30 seconds of code
January 7, 2024 - const toTimestamp = date => Math.floor(date.getTime() / 1000); const fromTimestamp = timestamp => new Date(timestamp * 1000); toTimestamp(new Date('2024-01-04')); // 1704326400 fromTimestamp(1704326400); // 2024-01-04T00:00:00.000Z ... Quickly and easily determine if a given JavaScript Date object is a weekday or weekend. ... Leverage the Date object to check if a given date is inside business hours.
🌐
InfluxData
influxdata.com › home › how to get, convert & format javascript date from timestamp | influxdata
How to Get, Convert & Format JavaScript Date From Timestamp | InfluxData
February 10, 2023 - The Date.now() method is a built-in function in JavaScript that allows developers to retrieve the current timestamp quickly. Its primary advantage is that it returns the number of milliseconds, rather than seconds or minutes, since January 1, ...