How to Get the Current Unix Timestamp (Terminal, JavaScript, Python)
Get the current Unix timestamp in seconds or milliseconds with date +%s, Date.now(), time.time(), SQL or Excel, and check the value with a timestamp converter.
The short answer
Run date +%s in a Linux or macOS terminal, Date.now() in JavaScript (milliseconds) or int(time.time()) in Python (seconds). A present-day timestamp has 10 digits in seconds and 13 in milliseconds. To see what any timestamp means as a date, paste it into the Unix Timestamp Converter, or click Use current time to get the current value without writing any code.
Quick reference
| Environment | Seconds | Milliseconds |
|---|---|---|
| Linux or macOS shell | date +%s | date +%s%3N (GNU date only) |
| Windows PowerShell | [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() | [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() |
| JavaScript or Node.js | Math.floor(Date.now() / 1000) | Date.now() |
| Python | int(time.time()) | time.time_ns() // 1_000_000 |
| PostgreSQL | SELECT EXTRACT(EPOCH FROM now())::bigint; | SELECT (EXTRACT(EPOCH FROM now()) * 1000)::bigint; |
| MySQL | SELECT UNIX_TIMESTAMP(); | SELECT ROUND(UNIX_TIMESTAMP(NOW(3)) * 1000); |
| Excel or Google Sheets | =ROUND((NOW()-DATE(1970,1,1))*86400,0) (see note) | multiply the seconds result by 1000 |
Each of these returns the number of seconds (or milliseconds) since 00:00:00 UTC on 1 January 1970, the Unix epoch.
Terminal
Linux and macOS
date +%s
This prints the current time in whole seconds, such as 1794229424. On Linux with GNU coreutils you can add milliseconds:
date +%s%3N
The macOS version of date doesn't support %N, so use Python or Node for milliseconds there.
To go the other way, from a timestamp to a readable date:
- GNU Linux:
date -d @1767225600 -uprints Thu Jan 1 00:00:00 UTC 2026 - macOS:
date -r 1767225600 -u
Add TZ=Asia/Kolkata before the command to see the same moment in Indian time: 05:30 IST on 1 January 2026.
Windows PowerShell
[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()
Use ToUnixTimeMilliseconds() for milliseconds.
JavaScript and Node.js
Date.now()(milliseconds, e.g. 1794229424927)Math.floor(Date.now() / 1000)(seconds, e.g. 1794229424)
Date.now() always works in milliseconds. A common bug is to pass a seconds value to new Date(), which expects milliseconds, and get a date in January 1970. Multiply seconds by 1000 first: new Date(1767225600 * 1000).
Python
import timeint(time.time())(seconds)time.time_ns() // 1_000_000(milliseconds)
time.time() returns a float with fractions of a second; wrap it in int() for a whole number. To convert back with an explicit time zone:
from datetime import datetime, timezonedatetime.fromtimestamp(1767225600, tz=timezone.utc)
Passing tz avoids surprises from the server's local time zone.
Other languages
The same idea, one line each:
- Java:
Instant.now().getEpochSecond()for seconds,System.currentTimeMillis()for milliseconds - Go:
time.Now().Unix()for seconds,time.Now().UnixMilli()for milliseconds - PHP:
time()for seconds,(int) round(microtime(true) * 1000)for milliseconds - C# / .NET:
DateTimeOffset.UtcNow.ToUnixTimeSeconds(), the same method PowerShell uses
Whichever language you use, check which unit a library function returns before you store or compare the value. Mixing a seconds value from one service with a milliseconds value from another is the most common timestamp bug in APIs and logs.
SQL
- PostgreSQL:
EXTRACT(EPOCH FROM now())returns seconds with a fractional part, so cast to bigint for whole seconds. - MySQL:
UNIX_TIMESTAMP()with no argument returns the current timestamp in seconds. - SQLite:
SELECT strftime('%s','now');returns seconds as text.
Excel and Google Sheets
Spreadsheets store dates as days, so subtract the epoch and multiply by 86,400 seconds per day:
=ROUND((NOW()-DATE(1970,1,1))*86400,0)
Note: NOW() uses your computer's or spreadsheet's local time, not UTC. In India, the result will be 19,800 seconds (5 hours 30 minutes) too high unless you subtract that offset. For converting the other way in a sheet, see how to convert a Unix timestamp to a date in Excel or Google Sheets.
Getting and checking a timestamp with the converter
The Unix Timestamp Converter is the quickest way to grab the current value or check one your code produced.
If the converted date is in 1970, you've entered seconds while ms is selected. If it's thousands of years away, you've entered milliseconds while s is selected.
Seconds vs milliseconds: how to tell
| Digits | Likely unit | Example | Means |
|---|---|---|---|
| 10 | Seconds | 1767225600 | 1 Jan 2026, 00:00 UTC |
| 13 | Milliseconds | 1767225600000 | Same moment |
Unix-style tools, PHP and most databases default to seconds. JavaScript, Java's System.currentTimeMillis() and many APIs use milliseconds. When two systems disagree by a factor of 1,000, this is nearly always the cause. For a deeper look, including the year 2038 problem, read Unix timestamps explained.
Common mistakes
- Mixing units. Store one unit consistently and name fields clearly, such as created_at_ms.
- Assuming the timestamp includes a time zone. It doesn't. It's UTC by definition; time zones only affect display.
- Building timestamps from local date strings. Parsing "2026-01-01 00:00" without a zone uses the machine's local time, which can shift results by hours. See how to convert a date to a Unix timestamp for the 5:30-hour error.
- Using a float where an integer is expected. Round or floor Python's
time.time()before storing it in an integer column.
Frequently asked questions
How do I get the current Unix timestamp in the terminal?
On Linux and macOS run date +%s for seconds. On GNU Linux, date +%s%3N gives milliseconds. In Windows PowerShell, [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() returns seconds.
How do I get the current timestamp in JavaScript?
Date.now() returns milliseconds since 1 January 1970 UTC. For seconds, use Math.floor(Date.now() / 1000).
How do I get the current timestamp in Python?
int(time.time()) after import time gives whole seconds. time.time_ns() // 1_000_000 gives milliseconds.
How can I tell if a timestamp is in seconds or milliseconds?
For present-day dates, a seconds timestamp has 10 digits and a milliseconds timestamp has 13. If you read a 13-digit value as seconds, you get a date tens of thousands of years in the future.
Does a Unix timestamp depend on my time zone?
No. A Unix timestamp counts seconds since 00:00:00 UTC on 1 January 1970, so it is the same everywhere at the same moment. Time zones only matter when you convert it to a readable date.
Put this guide into practice with our free online tool — no signup required.
Open tool