Unixdates

Unix epoch in every language

Copy-paste snippets for getting the current Unix timestamp, or converting a date string to an epoch, in 14 popular languages and databases.

Bash / shell

Current epoch

date +%s

From a date string

date -d "2026-04-22 12:00:00 UTC" +%s

Uses GNU date. On macOS/BSD, use: date -jf "%Y-%m-%d %H:%M:%S" "2026-04-22 12:00:00" +%s

JavaScript

Current epoch

Math.floor(Date.now() / 1000)

From a date string

Math.floor(new Date('2026-04-22T12:00:00Z').getTime() / 1000)

Date.now() returns milliseconds — divide by 1000 for seconds.

TypeScript

Current epoch

const now: number = Math.floor(Date.now() / 1000);

Python

Current epoch

import time
time.time()

From a date string

from datetime import datetime, timezone
int(datetime(2026, 4, 22, 12, tzinfo=timezone.utc).timestamp())

time.time() returns a float with sub-second precision. Wrap with int() for seconds.

PHP

Current epoch

time();

From a date string

strtotime('2026-04-22 12:00:00 UTC');

Go

Current epoch

time.Now().Unix()

From a date string

time.Date(2026, 4, 22, 12, 0, 0, 0, time.UTC).Unix()

Rust

Current epoch

use std::time::{SystemTime, UNIX_EPOCH};
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()

Java

Current epoch

Instant.now().getEpochSecond()

From a date string

Instant.parse("2026-04-22T12:00:00Z").getEpochSecond()

Requires java.time.Instant (Java 8+).

C#

Current epoch

DateTimeOffset.UtcNow.ToUnixTimeSeconds()

From a date string

new DateTimeOffset(2026, 4, 22, 12, 0, 0, TimeSpan.Zero).ToUnixTimeSeconds()

Ruby

Current epoch

Time.now.to_i

From a date string

Time.utc(2026, 4, 22, 12, 0, 0).to_i

Swift

Current epoch

Int(Date().timeIntervalSince1970)

Kotlin

Current epoch

System.currentTimeMillis() / 1000

SQL (PostgreSQL)

Current epoch

SELECT EXTRACT(EPOCH FROM NOW())::bigint;

From a date string

SELECT EXTRACT(EPOCH FROM TIMESTAMP '2026-04-22 12:00:00')::bigint;

SQL (MySQL)

Current epoch

SELECT UNIX_TIMESTAMP();

From a date string

SELECT UNIX_TIMESTAMP('2026-04-22 12:00:00');

Need the other direction? The Unixdates converter turns any epoch into a human-readable date, in any timezone.