How to Convert Unix Timestamps in Every Programming Language (2026 Edition)

Every language handles timestamps slightly differently. Some count in seconds, others in milliseconds. Some have dedicated datetime types, others use raw integers. This guide gives you modern, idiomatic, copy-paste-ready code for the three operations every developer needs: getting the current epoch, converting epoch to date, and converting date to epoch.
All examples use the current recommended APIs for each language — no deprecated functions, no legacy patterns. If you're still using SimpleDateFormat in Java or time.gmtime() in Python, it's time to upgrade.
Get auto-filled code snippets for your active timestampJavaScript / TypeScript
JavaScript's Date object works in milliseconds, not seconds. The most common mistake is forgetting to multiply or divide by 1,000.
// Get current epoch (seconds)const epoch = Math.floor(Date.now() / 1000);// Epoch → Dateconst date = new Date(1771387200 * 1000);console.log(date.toISOString()); // "2026-02-18T12:00:00.000Z"// Date → Epochconst epoch2 = Math.floor(new Date('2026-02-18T12:00:00Z').getTime() / 1000);
Python
Python 3 has excellent timezone-aware datetime support. Always use timezone-aware objects with timezone.utc — naive datetimes are a common source of bugs.
from datetime import datetime, timezoneimport time# Get current epochepoch = int(time.time())# Epoch → Datedt = datetime.fromtimestamp(1771387200, tz=timezone.utc)print(dt.isoformat()) # "2026-02-18T12:00:00+00:00"# Date → Epochdt = datetime(2026, 2, 18, 12, 0, 0, tzinfo=timezone.utc)epoch = int(dt.timestamp())
Go
Go's time package is one of the best-designed time APIs in any language. The unusual reference time "Mon Jan 2 15:04:05 MST 2006" is used for format strings instead of strftime-style codes.
package mainimport ("fmt""time")func main() {// Get current epochepoch := time.Now().Unix()// Epoch → Datet := time.Unix(1771387200, 0).UTC()fmt.Println(t.Format(time.RFC3339)) // "2026-02-18T12:00:00Z"// Date → Epocht2 := time.Date(2026, 2, 18, 12, 0, 0, 0, time.UTC)fmt.Println(t2.Unix())}
Rust
use std::time::{SystemTime, UNIX_EPOCH, Duration};fn main() {// Get current epochlet epoch = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();// Epoch → SystemTimelet time = UNIX_EPOCH + Duration::from_secs(1771387200);// For human-readable formatting, use the chrono crate:// use chrono::{DateTime, Utc, NaiveDateTime};// let dt = DateTime::<Utc>::from_timestamp(1771387200, 0).unwrap();}
Java
Use java.time.Instant (Java 8+). Do not use Date, Calendar, or SimpleDateFormat — they are legacy APIs with timezone bugs and thread safety issues.
import java.time.Instant;import java.time.ZoneOffset;import java.time.LocalDateTime;// Get current epochlong epoch = Instant.now().getEpochSecond();// Epoch → DateInstant instant = Instant.ofEpochSecond(1771387200);System.out.println(instant); // "2026-02-18T12:00:00Z"// Date → Epochlong epoch2 = LocalDateTime.of(2026, 2, 18, 12, 0, 0).toEpochSecond(ZoneOffset.UTC);
C#
// Get current epochlong epoch = DateTimeOffset.UtcNow.ToUnixTimeSeconds();// Epoch → DateDateTimeOffset dt = DateTimeOffset.FromUnixTimeSeconds(1771387200);Console.WriteLine(dt.ToString("o")); // "2026-02-18T12:00:00.0000000+00:00"// Date → Epochlong epoch2 = new DateTimeOffset(2026, 2, 18, 12, 0, 0, TimeSpan.Zero).ToUnixTimeSeconds();
PHP
<?php// Get current epoch$epoch = time();// Epoch → Date$date = date('c', 1771387200); // "2026-02-18T12:00:00+00:00"// Date → Epoch$epoch = strtotime('2026-02-18T12:00:00Z');// Or with DateTime:$dt = new DateTime('2026-02-18T12:00:00Z');$epoch = $dt->getTimestamp();
Bash
# Get current epochepoch=$(date +%s)# Epoch → Datedate -d @1771387200 --iso-8601=seconds # Linuxdate -r 1771387200 +%Y-%m-%dT%H:%M:%S # macOS# Date → Epochdate -d "2026-02-18T12:00:00Z" +%s # Linuxdate -j -f "%Y-%m-%dT%H:%M:%S" "2026-02-18T12:00:00" +%s # macOS
SQL (MySQL, PostgreSQL, SQLite)
-- MySQLSELECT UNIX_TIMESTAMP(); -- Current epochSELECT FROM_UNIXTIME(1771387200); -- Epoch → DateSELECT UNIX_TIMESTAMP('2026-02-18 12:00:00'); -- Date → Epoch-- PostgreSQLSELECT extract(epoch FROM now()); -- Current epochSELECT to_timestamp(1771387200); -- Epoch → DateSELECT extract(epoch FROM '2026-02-18 12:00:00'::timestamp); -- Date → Epoch-- SQLiteSELECT strftime('%s', 'now'); -- Current epochSELECT datetime(1771387200, 'unixepoch'); -- Epoch → DateSELECT strftime('%s', '2026-02-18 12:00:00'); -- Date → Epoch
For all 20+ supported languages with auto-filled values from your active conversion, use the code snippet generator:
Open the full code snippet generator