Unix 时间戳转换与检测器 — 实时转换、比较并检测时间戳

Unix 时间戳
—

正在加载实时 timestamp...

复制暂停刷新粘贴
快速转换器

粘贴 Unix 时间戳或日期字符串,即可在 Unix 秒、毫秒、ISO 8601、UTC、本地化时间和相对时间之间即时转换。

全球时区

用本地化格式比较全球 40+ 个时区的当前时间。

时间戳代码示例

查看主流编程语言中获取、格式化、解析和转换 Unix 时间戳的示例。

// Current Unix timestamp (seconds)
const now = Math.floor(Date.now() / 1000);

// Current timestamp in milliseconds
const ms = Date.now();

// Convert timestamp to Date object
const date = new Date(1710492223 * 1000);

// Format to ISO 8601 string
date.toISOString(); // "2024-03-15T12:23:43.000Z"

// Format to locale string
date.toLocaleString("en-US", {
  timeZone: "America/New_York",
  dateStyle: "full",
  timeStyle: "long",
});

// Parse a date string to timestamp
const ts = new Date("2024-03-15T08:00:00Z").getTime() / 1000;

// Add 7 days to a timestamp
const nextWeek = now + 7 * 24 * 60 * 60;

// Compare two timestamps
const isExpired = now > expiresAt;

// Get individual components
const year = date.getFullYear();
const month = date.getMonth() + 1; // 0-indexed
const day = date.getDate();
const hours = date.getHours();
// Current Unix timestamp (seconds)
const now = Math.floor(Date.now() / 1000);

// Current timestamp in milliseconds
const ms = Date.now();

// Convert timestamp to Date object
const date = new Date(1710492223 * 1000);

// Format to ISO 8601 string
date.toISOString(); // "2024-03-15T12:23:43.000Z"

// Format to locale string
date.toLocaleString("en-US", {
  timeZone: "America/New_York",
  dateStyle: "full",
  timeStyle: "long",
});

// Parse a date string to timestamp
const ts = new Date("2024-03-15T08:00:00Z").getTime() / 1000;

// Add 7 days to a timestamp
const nextWeek = now + 7 * 24 * 60 * 60;

// Compare two timestamps
const isExpired = now > expiresAt;

// Get individual components
const year = date.getFullYear();
const month = date.getMonth() + 1; // 0-indexed
const day = date.getDate();
const hours = date.getHours();
import time
from datetime import datetime, timezone, timedelta

# Current Unix timestamp (seconds)
now = int(time.time())

# Current timestamp in milliseconds
ms = int(time.time() * 1000)

# Convert timestamp to datetime
dt = datetime.fromtimestamp(1710492223, tz=timezone.utc)

# Format to ISO 8601
dt.isoformat()  # "2024-03-15T12:23:43+00:00"

# Custom format with strftime
dt.strftime("%Y-%m-%d %H:%M:%S")  # "2024-03-15 12:23:43"
dt.strftime("%B %d, %Y %I:%M %p")  # "March 15, 2024 12:23 PM"

# Parse a date string to timestamp
parsed = datetime.strptime("2024-03-15 08:00:00", "%Y-%m-%d %H:%M:%S")
ts = int(parsed.replace(tzinfo=timezone.utc).timestamp())

# Add 7 days
next_week = dt + timedelta(days=7)

# Convert between timezones
eastern = dt.astimezone(timezone(timedelta(hours=-5)))

# Get individual components
year, month, day = dt.year, dt.month, dt.day
import time
from datetime import datetime, timezone, timedelta

# Current Unix timestamp (seconds)
now = int(time.time())

# Current timestamp in milliseconds
ms = int(time.time() * 1000)

# Convert timestamp to datetime
dt = datetime.fromtimestamp(1710492223, tz=timezone.utc)

# Format to ISO 8601
dt.isoformat()  # "2024-03-15T12:23:43+00:00"

# Custom format with strftime
dt.strftime("%Y-%m-%d %H:%M:%S")  # "2024-03-15 12:23:43"
dt.strftime("%B %d, %Y %I:%M %p")  # "March 15, 2024 12:23 PM"

# Parse a date string to timestamp
parsed = datetime.strptime("2024-03-15 08:00:00", "%Y-%m-%d %H:%M:%S")
ts = int(parsed.replace(tzinfo=timezone.utc).timestamp())

# Add 7 days
next_week = dt + timedelta(days=7)

# Convert between timezones
eastern = dt.astimezone(timezone(timedelta(hours=-5)))

# Get individual components
year, month, day = dt.year, dt.month, dt.day
// Type-safe timestamp utilities

// Current Unix timestamp (seconds)
const now: number = Math.floor(Date.now() / 1000);

// Convert timestamp to Date
function fromUnix(ts: number): Date {
  return new Date(ts * 1000);
}

// Format with Intl.DateTimeFormat (no library needed)
function formatDate(ts: number, tz: string = "UTC"): string {
  return new Intl.DateTimeFormat("en-US", {
    timeZone: tz,
    year: "numeric",
    month: "short",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
    hour12: false,
  }).format(fromUnix(ts));
}

// Relative time (e.g. "3 hours ago")
function timeAgo(ts: number): string {
  const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
  const diff = ts - Math.floor(Date.now() / 1000);
  const absDiff = Math.abs(diff);

  if (absDiff < 60) return rtf.format(diff, "second");
  if (absDiff < 3600) return rtf.format(Math.round(diff / 60), "minute");
  if (absDiff < 86400) return rtf.format(Math.round(diff / 3600), "hour");
  return rtf.format(Math.round(diff / 86400), "day");
}

// ISO 8601 to Unix timestamp
const ts = Math.floor(new Date("2024-03-15T08:00:00Z").getTime() / 1000);
// Type-safe timestamp utilities

// Current Unix timestamp (seconds)
const now: number = Math.floor(Date.now() / 1000);

// Convert timestamp to Date
function fromUnix(ts: number): Date {
  return new Date(ts * 1000);
}

// Format with Intl.DateTimeFormat (no library needed)
function formatDate(ts: number, tz: string = "UTC"): string {
  return new Intl.DateTimeFormat("en-US", {
    timeZone: tz,
    year: "numeric",
    month: "short",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
    hour12: false,
  }).format(fromUnix(ts));
}

// Relative time (e.g. "3 hours ago")
function timeAgo(ts: number): string {
  const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
  const diff = ts - Math.floor(Date.now() / 1000);
  const absDiff = Math.abs(diff);

  if (absDiff < 60) return rtf.format(diff, "second");
  if (absDiff < 3600) return rtf.format(Math.round(diff / 60), "minute");
  if (absDiff < 86400) return rtf.format(Math.round(diff / 3600), "hour");
  return rtf.format(Math.round(diff / 86400), "day");
}

// ISO 8601 to Unix timestamp
const ts = Math.floor(new Date("2024-03-15T08:00:00Z").getTime() / 1000);
import java.time.*;
import java.time.format.DateTimeFormatter;

public class TimestampExample {
    public static void main(String[] args) {
        // Current Unix timestamp (seconds)
        long now = Instant.now().getEpochSecond();

        // Current timestamp in milliseconds
        long ms = System.currentTimeMillis();

        // Convert timestamp to Instant
        Instant instant = Instant.ofEpochSecond(1710492223L);

        // Format to ISO 8601
        instant.toString(); // "2024-03-15T12:23:43Z"

        // Convert to ZonedDateTime for formatting
        ZonedDateTime zdt = instant.atZone(ZoneId.of("America/New_York"));
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
        String formatted = zdt.format(fmt); // "2024-03-15 08:23:43 EDT"

        // Parse a date string to timestamp
        LocalDateTime ldt = LocalDateTime.parse("2024-03-15T08:00:00");
        long ts = ldt.toEpochSecond(ZoneOffset.UTC);

        // Add 7 days
        Instant nextWeek = instant.plus(Duration.ofDays(7));

        // Compare timestamps
        boolean isAfter = Instant.now().isAfter(instant);
    }
}
import java.time.*;
import java.time.format.DateTimeFormatter;

public class TimestampExample {
    public static void main(String[] args) {
        // Current Unix timestamp (seconds)
        long now = Instant.now().getEpochSecond();

        // Current timestamp in milliseconds
        long ms = System.currentTimeMillis();

        // Convert timestamp to Instant
        Instant instant = Instant.ofEpochSecond(1710492223L);

        // Format to ISO 8601
        instant.toString(); // "2024-03-15T12:23:43Z"

        // Convert to ZonedDateTime for formatting
        ZonedDateTime zdt = instant.atZone(ZoneId.of("America/New_York"));
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
        String formatted = zdt.format(fmt); // "2024-03-15 08:23:43 EDT"

        // Parse a date string to timestamp
        LocalDateTime ldt = LocalDateTime.parse("2024-03-15T08:00:00");
        long ts = ldt.toEpochSecond(ZoneOffset.UTC);

        // Add 7 days
        Instant nextWeek = instant.plus(Duration.ofDays(7));

        // Compare timestamps
        boolean isAfter = Instant.now().isAfter(instant);
    }
}
package main

import (
	"fmt"
	"time"
)

func main() {
	// Current Unix timestamp (seconds)
	now := time.Now().Unix()

	// Current timestamp in milliseconds
	ms := time.Now().UnixMilli()

	// Convert timestamp to Time
	t := time.Unix(1710492223, 0).UTC()

	// Format to ISO 8601
	t.Format(time.RFC3339) // "2024-03-15T12:23:43Z"

	// Custom format (Go uses reference time: Mon Jan 2 15:04:05 2006)
	t.Format("2006-01-02 15:04:05") // "2024-03-15 12:23:43"
	t.Format("Jan 02, 2006 3:04 PM") // "Mar 15, 2024 12:23 PM"

	// Parse a date string to timestamp
	parsed, _ := time.Parse("2006-01-02 15:04:05", "2024-03-15 08:00:00")
	ts := parsed.Unix()

	// Add 7 days
	nextWeek := t.AddDate(0, 0, 7)

	// Convert to a specific timezone
	loc, _ := time.LoadLocation("America/New_York")
	eastern := t.In(loc)

	// Get individual components
	year, month, day := t.Date()
	hour, min, sec := t.Clock()

	fmt.Println(now, ms, ts, nextWeek, eastern, year, month, day, hour, min, sec)
}
package main

import (
	"fmt"
	"time"
)

func main() {
	// Current Unix timestamp (seconds)
	now := time.Now().Unix()

	// Current timestamp in milliseconds
	ms := time.Now().UnixMilli()

	// Convert timestamp to Time
	t := time.Unix(1710492223, 0).UTC()

	// Format to ISO 8601
	t.Format(time.RFC3339) // "2024-03-15T12:23:43Z"

	// Custom format (Go uses reference time: Mon Jan 2 15:04:05 2006)
	t.Format("2006-01-02 15:04:05") // "2024-03-15 12:23:43"
	t.Format("Jan 02, 2006 3:04 PM") // "Mar 15, 2024 12:23 PM"

	// Parse a date string to timestamp
	parsed, _ := time.Parse("2006-01-02 15:04:05", "2024-03-15 08:00:00")
	ts := parsed.Unix()

	// Add 7 days
	nextWeek := t.AddDate(0, 0, 7)

	// Convert to a specific timezone
	loc, _ := time.LoadLocation("America/New_York")
	eastern := t.In(loc)

	// Get individual components
	year, month, day := t.Date()
	hour, min, sec := t.Clock()

	fmt.Println(now, ms, ts, nextWeek, eastern, year, month, day, hour, min, sec)
}
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc, Duration, FixedOffset};

fn main() {
    // Current Unix timestamp (seconds)
    let now = Utc::now().timestamp();

    // Current timestamp in milliseconds
    let ms = Utc::now().timestamp_millis();

    // Convert timestamp to DateTime
    let dt = DateTime::from_timestamp(1710492223, 0).unwrap();

    // Format to ISO 8601
    dt.to_rfc3339(); // "2024-03-15T12:23:43+00:00"

    // Custom format with strftime
    dt.format("%Y-%m-%d %H:%M:%S").to_string(); // "2024-03-15 12:23:43"
    dt.format("%B %d, %Y %I:%M %p").to_string(); // "March 15, 2024 12:23 PM"

    // Parse a date string to timestamp
    let parsed = NaiveDateTime::parse_from_str(
        "2024-03-15 08:00:00", "%Y-%m-%d %H:%M:%S"
    ).unwrap();
    let ts = parsed.and_utc().timestamp();

    // Add 7 days
    let next_week = dt + Duration::days(7);

    // Convert to a fixed offset timezone (UTC-5)
    let eastern = FixedOffset::west_opt(5 * 3600).unwrap();
    let est_time = dt.with_timezone(&eastern);

    println!("{now} {ms} {ts} {next_week} {est_time}");
}
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc, Duration, FixedOffset};

fn main() {
    // Current Unix timestamp (seconds)
    let now = Utc::now().timestamp();

    // Current timestamp in milliseconds
    let ms = Utc::now().timestamp_millis();

    // Convert timestamp to DateTime
    let dt = DateTime::from_timestamp(1710492223, 0).unwrap();

    // Format to ISO 8601
    dt.to_rfc3339(); // "2024-03-15T12:23:43+00:00"

    // Custom format with strftime
    dt.format("%Y-%m-%d %H:%M:%S").to_string(); // "2024-03-15 12:23:43"
    dt.format("%B %d, %Y %I:%M %p").to_string(); // "March 15, 2024 12:23 PM"

    // Parse a date string to timestamp
    let parsed = NaiveDateTime::parse_from_str(
        "2024-03-15 08:00:00", "%Y-%m-%d %H:%M:%S"
    ).unwrap();
    let ts = parsed.and_utc().timestamp();

    // Add 7 days
    let next_week = dt + Duration::days(7);

    // Convert to a fixed offset timezone (UTC-5)
    let eastern = FixedOffset::west_opt(5 * 3600).unwrap();
    let est_time = dt.with_timezone(&eastern);

    println!("{now} {ms} {ts} {next_week} {est_time}");
}
<?php
// Current Unix timestamp (seconds)
$now = time();

// Current timestamp in milliseconds
$ms = (int)(microtime(true) * 1000);

// Convert timestamp to formatted date
$date = date('Y-m-d H:i:s', 1710492223); // "2024-03-15 12:23:43"

// Format to ISO 8601
$iso = date('c', 1710492223); // "2024-03-15T12:23:43+00:00"

// Custom format
date('F j, Y g:i A', 1710492223); // "March 15, 2024 12:23 PM"

// Parse a date string to timestamp
$ts = strtotime('2024-03-15 08:00:00');

// Using DateTime object (recommended)
$dt = new DateTime('@1710492223');
$dt->setTimezone(new DateTimeZone('America/New_York'));
echo $dt->format('Y-m-d H:i:s T'); // "2024-03-15 08:23:43 EDT"

// Add 7 days
$dt->modify('+7 days');

// Create from format
$parsed = DateTime::createFromFormat('Y-m-d H:i:s', '2024-03-15 08:00:00');
$ts = $parsed->getTimestamp();

// Compare dates
$isExpired = time() > $expiresAt;
<?php
// Current Unix timestamp (seconds)
$now = time();

// Current timestamp in milliseconds
$ms = (int)(microtime(true) * 1000);

// Convert timestamp to formatted date
$date = date('Y-m-d H:i:s', 1710492223); // "2024-03-15 12:23:43"

// Format to ISO 8601
$iso = date('c', 1710492223); // "2024-03-15T12:23:43+00:00"

// Custom format
date('F j, Y g:i A', 1710492223); // "March 15, 2024 12:23 PM"

// Parse a date string to timestamp
$ts = strtotime('2024-03-15 08:00:00');

// Using DateTime object (recommended)
$dt = new DateTime('@1710492223');
$dt->setTimezone(new DateTimeZone('America/New_York'));
echo $dt->format('Y-m-d H:i:s T'); // "2024-03-15 08:23:43 EDT"

// Add 7 days
$dt->modify('+7 days');

// Create from format
$parsed = DateTime::createFromFormat('Y-m-d H:i:s', '2024-03-15 08:00:00');
$ts = $parsed->getTimestamp();

// Compare dates
$isExpired = time() > $expiresAt;
require 'time'

# Current Unix timestamp (seconds)
now = Time.now.to_i

# Current timestamp in milliseconds
ms = (Time.now.to_f * 1000).to_i

# Convert timestamp to Time object
t = Time.at(1710492223).utc

# Format to ISO 8601
t.iso8601  # "2024-03-15T12:23:43Z"

# Custom format with strftime
t.strftime('%Y-%m-%d %H:%M:%S')      # "2024-03-15 12:23:43"
t.strftime('%B %d, %Y %I:%M %p')     # "March 15, 2024 12:23 PM"

# Parse a date string to timestamp
ts = Time.parse('2024-03-15 08:00:00 UTC').to_i

# Add 7 days (seconds)
next_week = t + (7 * 24 * 60 * 60)

# Convert to a specific timezone
ENV['TZ'] = 'America/New_York'
eastern = Time.at(1710492223)
ENV['TZ'] = nil

# Get individual components
year  = t.year
month = t.month
day   = t.day
hour  = t.hour
require 'time'

# Current Unix timestamp (seconds)
now = Time.now.to_i

# Current timestamp in milliseconds
ms = (Time.now.to_f * 1000).to_i

# Convert timestamp to Time object
t = Time.at(1710492223).utc

# Format to ISO 8601
t.iso8601  # "2024-03-15T12:23:43Z"

# Custom format with strftime
t.strftime('%Y-%m-%d %H:%M:%S')      # "2024-03-15 12:23:43"
t.strftime('%B %d, %Y %I:%M %p')     # "March 15, 2024 12:23 PM"

# Parse a date string to timestamp
ts = Time.parse('2024-03-15 08:00:00 UTC').to_i

# Add 7 days (seconds)
next_week = t + (7 * 24 * 60 * 60)

# Convert to a specific timezone
ENV['TZ'] = 'America/New_York'
eastern = Time.at(1710492223)
ENV['TZ'] = nil

# Get individual components
year  = t.year
month = t.month
day   = t.day
hour  = t.hour
using System;
using System.Globalization;

// Current Unix timestamp (seconds)
long now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

// Current timestamp in milliseconds
long ms = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

// Convert timestamp to DateTimeOffset
var dto = DateTimeOffset.FromUnixTimeSeconds(1710492223);

// Format to ISO 8601
dto.ToString("o"); // "2024-03-15T12:23:43.0000000+00:00"

// Custom format
dto.ToString("yyyy-MM-dd HH:mm:ss");       // "2024-03-15 12:23:43"
dto.ToString("MMMM dd, yyyy h:mm tt");     // "March 15, 2024 12:23 PM"

// Parse a date string to timestamp
var parsed = DateTimeOffset.Parse("2024-03-15T08:00:00Z");
long ts = parsed.ToUnixTimeSeconds();

// Add 7 days
var nextWeek = dto.AddDays(7);

// Convert to a specific timezone
var eastern = TimeZoneInfo.FindSystemTimeZoneById("America/New_York");
var estTime = TimeZoneInfo.ConvertTime(dto, eastern);

// Compare timestamps
bool isExpired = DateTimeOffset.UtcNow > dto;
using System;
using System.Globalization;

// Current Unix timestamp (seconds)
long now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

// Current timestamp in milliseconds
long ms = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

// Convert timestamp to DateTimeOffset
var dto = DateTimeOffset.FromUnixTimeSeconds(1710492223);

// Format to ISO 8601
dto.ToString("o"); // "2024-03-15T12:23:43.0000000+00:00"

// Custom format
dto.ToString("yyyy-MM-dd HH:mm:ss");       // "2024-03-15 12:23:43"
dto.ToString("MMMM dd, yyyy h:mm tt");     // "March 15, 2024 12:23 PM"

// Parse a date string to timestamp
var parsed = DateTimeOffset.Parse("2024-03-15T08:00:00Z");
long ts = parsed.ToUnixTimeSeconds();

// Add 7 days
var nextWeek = dto.AddDays(7);

// Convert to a specific timezone
var eastern = TimeZoneInfo.FindSystemTimeZoneById("America/New_York");
var estTime = TimeZoneInfo.ConvertTime(dto, eastern);

// Compare timestamps
bool isExpired = DateTimeOffset.UtcNow > dto;
import Foundation

// Current Unix timestamp (seconds)
let now = Int(Date().timeIntervalSince1970)

// Current timestamp in milliseconds
let ms = Int(Date().timeIntervalSince1970 * 1000)

// Convert timestamp to Date
let date = Date(timeIntervalSince1970: 1710492223)

// Format to ISO 8601
let isoFormatter = ISO8601DateFormatter()
isoFormatter.string(from: date) // "2024-03-15T12:23:43Z"

// Custom format with DateFormatter
let fmt = DateFormatter()
fmt.dateFormat = "yyyy-MM-dd HH:mm:ss"
fmt.timeZone = TimeZone(identifier: "UTC")
fmt.string(from: date) // "2024-03-15 12:23:43"

// Locale-aware formatting
fmt.dateStyle = .full
fmt.timeStyle = .long
fmt.timeZone = TimeZone(identifier: "America/New_York")
fmt.string(from: date) // "Friday, March 15, 2024 at 8:23:43 AM EDT"

// Parse a date string to timestamp
fmt.dateFormat = "yyyy-MM-dd HH:mm:ss"
if let parsed = fmt.date(from: "2024-03-15 08:00:00") {
    let ts = Int(parsed.timeIntervalSince1970)
}

// Add 7 days
let nextWeek = Calendar.current.date(byAdding: .day, value: 7, to: date)!
import Foundation

// Current Unix timestamp (seconds)
let now = Int(Date().timeIntervalSince1970)

// Current timestamp in milliseconds
let ms = Int(Date().timeIntervalSince1970 * 1000)

// Convert timestamp to Date
let date = Date(timeIntervalSince1970: 1710492223)

// Format to ISO 8601
let isoFormatter = ISO8601DateFormatter()
isoFormatter.string(from: date) // "2024-03-15T12:23:43Z"

// Custom format with DateFormatter
let fmt = DateFormatter()
fmt.dateFormat = "yyyy-MM-dd HH:mm:ss"
fmt.timeZone = TimeZone(identifier: "UTC")
fmt.string(from: date) // "2024-03-15 12:23:43"

// Locale-aware formatting
fmt.dateStyle = .full
fmt.timeStyle = .long
fmt.timeZone = TimeZone(identifier: "America/New_York")
fmt.string(from: date) // "Friday, March 15, 2024 at 8:23:43 AM EDT"

// Parse a date string to timestamp
fmt.dateFormat = "yyyy-MM-dd HH:mm:ss"
if let parsed = fmt.date(from: "2024-03-15 08:00:00") {
    let ts = Int(parsed.timeIntervalSince1970)
}

// Add 7 days
let nextWeek = Calendar.current.date(byAdding: .day, value: 7, to: date)!
import java.time.*
import java.time.format.DateTimeFormatter

fun main() {
    // Current Unix timestamp (seconds)
    val now = Instant.now().epochSecond

    // Current timestamp in milliseconds
    val ms = System.currentTimeMillis()

    // Convert timestamp to Instant
    val instant = Instant.ofEpochSecond(1710492223L)

    // Format to ISO 8601
    instant.toString() // "2024-03-15T12:23:43Z"

    // Convert to ZonedDateTime for custom formatting
    val zdt = instant.atZone(ZoneId.of("America/New_York"))
    val fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z")
    zdt.format(fmt) // "2024-03-15 08:23:43 EDT"

    // Parse a date string to timestamp
    val parsed = LocalDateTime.parse("2024-03-15T08:00:00")
    val ts = parsed.toEpochSecond(ZoneOffset.UTC)

    // Add 7 days
    val nextWeek = instant.plus(Duration.ofDays(7))

    // Relative time calculation
    val duration = Duration.between(instant, Instant.now())
    println("${duration.toDays()} days ago")
}
import java.time.*
import java.time.format.DateTimeFormatter

fun main() {
    // Current Unix timestamp (seconds)
    val now = Instant.now().epochSecond

    // Current timestamp in milliseconds
    val ms = System.currentTimeMillis()

    // Convert timestamp to Instant
    val instant = Instant.ofEpochSecond(1710492223L)

    // Format to ISO 8601
    instant.toString() // "2024-03-15T12:23:43Z"

    // Convert to ZonedDateTime for custom formatting
    val zdt = instant.atZone(ZoneId.of("America/New_York"))
    val fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z")
    zdt.format(fmt) // "2024-03-15 08:23:43 EDT"

    // Parse a date string to timestamp
    val parsed = LocalDateTime.parse("2024-03-15T08:00:00")
    val ts = parsed.toEpochSecond(ZoneOffset.UTC)

    // Add 7 days
    val nextWeek = instant.plus(Duration.ofDays(7))

    // Relative time calculation
    val duration = Duration.between(instant, Instant.now())
    println("${duration.toDays()} days ago")
}

功能亮点

实时 Unix 时间戳

以毫秒精度实时更新 Unix 时间戳。可暂停、复制,或立即跳转到任意时间点。

全球时区比较

比较全球 30+ 个时区的当前时间,一眼查看 UTC 偏移和本地化格式。

日志时间戳检测

粘贴服务器日志或任意文本,自动检测并高亮 Unix、ISO 8601 和常见日志格式等多种时间戳。

快速时间跳转

一键跳转到今天、明天、周初、月初、年初或 Unix epoch 起点。

支持的时间戳格式

格式示例
Unix 秒1710492223
Unix 毫秒1710492245832
ISO 86012024-03-15T08:23:41.192Z
带偏移的 ISO 86012024-03-15T20:24:05+08:00
日期时间2024-03-15 08:23:42
常见日志格式15/Mar/2024:08:24:05 +0000
人类可读格式Mar 15, 2024 08:24:01

常见问题

Unix 时间戳(也称 Epoch time 或 POSIX time)是从 1970 年 1 月 1 日 00:00:00 UTC 至今经过的秒数。它广泛用于编程、数据库和服务器日志,是一种通用时间表示方式。

它可以自动检测 Unix 时间戳(秒和毫秒)、ISO 8601 日期、常见日志格式(Apache/Nginx)、人类可读日期字符串等。只需粘贴文本,时间戳会自动高亮。

不会。所有时间戳转换和检测都完全在浏览器内完成。你的数据不会离开设备,没有服务器请求,也没有数据收集。

可以。时区面板会同时显示全球 30+ 个时区的当前(或暂停)时间,方便跨地区协作。

持续增长的高效、隐私优先开发者工具集合。所有工具都在浏览器中运行,数据不会离开你的设备。

工具

JSON 解析器JSON Schema 校验器JSON 转换器JSON 转 TypeScriptOpenAPI 查看器代码格式化SQL 格式化cURL 转换器时间戳转换器Cron 解析器URL 编码器二维码工具IP 与 CIDR 计算器Gzip 与 Deflate 工具JWT 解码器JWT 验签与 JWK 工具哈希生成器密码与 TOTPBase64 编码器UUID 生成器图片元数据图片压缩Tiny 图片压缩器图片工具箱 Pro屏幕录制正则测试器文本 DiffMarkdown 与 Mermaid 预览颜色与对比度工具

法律

隐私政策服务条款

© 2026 ZPTools. 保留所有权利。