Back to tools

Time

Timestamp Converter

Convert between date time and Unix timestamps online with second and millisecond units plus common programming examples.

Date time to timestamp

Timestamp to date time

Unit

Common timestamp examples

JavaScript

const ms = Date.now();
const seconds = Math.floor(Date.now() / 1000);
const date = new Date(ms);

Python

import time, datetime
ms = int(time.time() * 1000)
seconds = int(time.time())
dt = datetime.datetime.fromtimestamp(seconds)

Java

long ms = System.currentTimeMillis();
long seconds = ms / 1000;
Instant instant = Instant.ofEpochMilli(ms);

PHP

$seconds = time();
$ms = (int) round(microtime(true) * 1000);
$date = date('Y-m-d H:i:s', $seconds);

Go

now := time.Now()
ms := now.UnixMilli()
seconds := now.Unix()
t := time.UnixMilli(ms)

C#

var now = DateTimeOffset.UtcNow;
long ms = now.ToUnixTimeMilliseconds();
long seconds = now.ToUnixTimeSeconds();
var dt = DateTimeOffset.FromUnixTimeMilliseconds(ms);

Ruby

seconds = Time.now.to_i
ms = (Time.now.to_f * 1000).to_i
time = Time.at(seconds)

Shell

date +%s
date +%s%3N
date -d @1715529600