Timestamp Converter
Unix timestamp and datetime mutual conversion with multiple timezone support
Your input never leaves your device
Current Time
Unix Timestamp: — (Seconds)
— (Milliseconds)
JavaScript
JavaScript Date & Unix timestamp
// Unix timestamp (ms)
const timestamp = Date.now();
// Unix timestamp (s)
const timestampSeconds = Math.floor(Date.now() / 1000);
// Timestamp to Date
const date = new Date(timestamp);
// Date to Timestamp
const timestampFromDate = date.getTime();Python
Python time & datetime
import time
from datetime import datetime
# Unix timestamp (s)
timestamp = int(time.time())
# Unix timestamp (ms)
timestamp_ms = int(time.time() * 1000)
# Timestamp to datetime
date = datetime.fromtimestamp(timestamp)
# Datetime to timestamp
timestamp_from_date = int(date.timestamp())PHP
PHP time() & date()
<?php
// Unix timestamp (s)
$timestamp = time();
// Unix timestamp (ms)
$timestamp_ms = round(microtime(true) * 1000);
// Timestamp to date
$date = date("Y-m-d H:i:s", $timestamp);
// Date to timestamp
$timestamp_from_date = strtotime($date);
?>Java
Java 8+ java.time.Instant
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
// Unix timestamp (ms)
long timestamp = System.currentTimeMillis();
// Unix timestamp (s)
long timestampSeconds = Instant.now().getEpochSecond();
// Timestamp to LocalDateTime
LocalDateTime date = LocalDateTime.ofInstant(
Instant.ofEpochMilli(timestamp),
ZoneId.systemDefault()
);
// LocalDateTime to timestamp
long timestampFromDate = date.atZone(ZoneId.systemDefault())
.toInstant().toEpochMilli();MySQL
MySQL UNIX_TIMESTAMP & FROM_UNIXTIME
-- Unix timestamp (s)
SELECT UNIX_TIMESTAMP();
-- Unix timestamp (ms)
SELECT UNIX_TIMESTAMP(NOW(3)) * 1000;
-- Timestamp to datetime
SELECT FROM_UNIXTIME(1704067200);
-- Datetime to timestamp
SELECT UNIX_TIMESTAMP("2024-01-01 12:00:00");Go
Go time.Now().Unix()
package main
import (
"fmt"
"time"
)
func main() {
// Unix timestamp (s)
timestamp := time.Now().Unix()
// Unix timestamp (ms)
timestampMs := time.Now().UnixMilli()
// Timestamp to Time
date := time.Unix(timestamp, 0)
// Time to timestamp
timestampFromDate := date.Unix()
}C#
C# DateTimeOffset
using System;
// Unix timestamp (s)
long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
// Unix timestamp (ms)
long timestampMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
// Timestamp to DateTime
DateTime date = DateTimeOffset.FromUnixTimeSeconds(timestamp).DateTime;
// DateTime to timestamp
long timestampFromDate = new DateTimeOffset(date).ToUnixTimeSeconds();Ruby
Ruby Time.now & Time.at
# Unix timestamp (s)
timestamp = Time.now.to_i
# Unix timestamp (ms)
timestamp_ms = (Time.now.to_f * 1000).to_i
# Timestamp to Time
date = Time.at(timestamp)
# Time to timestamp
timestamp_from_date = date.to_iSwift
Swift Foundation Date
import Foundation
// Unix timestamp (s)
let timestamp = Int(Date().timeIntervalSince1970)
// Unix timestamp (ms)
let timestampMs = Int(Date().timeIntervalSince1970 * 1000)
// Timestamp to Date
let date = Date(timeIntervalSince1970: TimeInterval(timestamp))
// Date to timestamp
let timestampFromDate = Int(date.timeIntervalSince1970)Kotlin
Kotlin java.time.Instant
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
// Unix timestamp (ms)
val timestamp = System.currentTimeMillis()
// Unix timestamp (s)
val timestampSeconds = Instant.now().epochSecond
// Timestamp to LocalDateTime
val date = LocalDateTime.ofInstant(
Instant.ofEpochMilli(timestamp),
ZoneId.systemDefault()
)
// LocalDateTime to timestamp
val timestampFromDate = date.atZone(ZoneId.systemDefault())
.toInstant().toEpochMilli()Unix timestamp is the number of seconds since January 1, 1970 00:00:00 UTC
Milliseconds timestamp is the number of milliseconds since January 1, 1970 00:00:00 UTC
Timezone is the time offset relative to UTC
Different programming languages and systems use different time formats
This page loads analytics and ad scripts. They never receive your files or what you type.
Recommended Tools
Image Compressor
Online image compression, reduces file size while maintaining quality
PDF Compressor
Online PDF file compression, reduces file size
JSON Formatter
Professional JSON formatting tool, supports beautification, compression, validation
Base64 Encoder/Decoder
Online Base64 encoding and decoding tool, supports text, image, file encoding