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 編碼器QR Code 工具IP 與 CIDR 計算器Gzip 與 Deflate 工具JWT 解碼器JWT 驗簽與 JWK 工具雜湊產生器密碼與 TOTPBase64 編碼器UUID 產生器圖片 metadata圖片壓縮Tiny 圖片壓縮器圖片工具箱 Pro螢幕錄製正則測試器文字 DiffMarkdown 與 Mermaid 預覽色彩與對比工具

法律

隱私權政策服務條款

© 2026 ZPTools. 保留所有權利。