时间
时间戳转换工具
在线进行时间与 Unix 时间戳相互转换,支持秒级和毫秒级时间戳,并提供常见编程语言示例。
主流语言时间戳示例
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