DevToolBox

Unix Timestamp Guide - Unix timeの基本と変換方法まとめ

APIのレスポンスやログに 1752307200 のような数字が出てきて、これが何を表すのか 分からず戸惑った経験はないでしょうか。unix timestamp(Unix time)は1970年1月1日 00:00:00 UTC からの経過秒数で時刻を表すシンプルな仕組みです。 この記事では定義から現在時刻の取得方法、秒/milliseconds表記の違い、主要言語での変換コード例まで、 初めて触れる人向けに基本をまとめます。

A Unix timestamp represents a moment in time as the number of seconds since 1970-01-01 00:00:00 UTC (the epoch). This guide covers the definition, how to get the current timestamp, seconds vs. milliseconds, and conversion recipes in five languages.

TL;DR

Timestamp Converter

unix timestampと日時を相互変換。現在時刻のtimestampをワンクリックで取得でき、秒・ミリ秒どちらの入力にも対応します。ブラウザ完結・外部送信なし。

今すぐ試す →

1. Unix timestampとは / What is a Unix timestamp

Unix timestampは「エポック(基準時刻 1970-01-01T00:00:00Z)からの経過秒数」を 表す1つの整数です。年月日・時分秒・曜日・タイムゾーンといった複雑な情報を持たず、 単純に「基準からどれだけ秒が経過したか」だけを表現します。

epoch (基準時刻):  1970-01-01T00:00:00Z  →  timestamp = 0
1週間後:            1970-01-08T00:00:00Z  →  timestamp = 604800  (60×60×24×7)
現在(2026年頃):     ...                   →  timestamp ≈ 17億後半〜18億台

Because it's a single UTC-based integer with no calendar or timezone baked in, a Unix timestamp is trivial to compare, sort, and store — which is why it's the default time representation in most APIs, databases, and log formats.

2. 現在のUnix timestampを取得する / Getting the current timestamp

// JavaScript
Math.floor(Date.now() / 1000)   // 秒
Date.now()                       // ミリ秒

# Python
import time
int(time.time())                 // 秒

// PHP
time()                            // 秒

// Go
time.Now().Unix()                 // 秒

// Java
Instant.now().getEpochSecond()    // 秒

# シェル (Linux / macOS)
date +%s                          // 秒

3. 秒とmillisecondsの見分け方 / Seconds vs. milliseconds

言語やAPIによって「秒」か「ミリ秒(milliseconds)」かの前提が異なります。桁数で機械的に 判別できるので、変換前に必ず確認する習慣をつけましょう。

単位現在の桁数代表例
秒 (s)10桁JWTの exp/iat、Python time.time()
ミリ秒 (ms)13桁JS Date.now()、Java System.currentTimeMillis()

秒とミリ秒を取り違えたまま new Date() に渡すと、1970年付近か遠い未来の日付が 表示されて気づけますが、タイムゾーンや二重変換など細かい落とし穴はUNIX timestamp 変換と落とし穴 で 詳しく解説しています。

4. 主要言語での変換コード / Conversion recipes

JavaScript / TypeScript

// timestamp(秒) → Date
const d = new Date(1752307200 * 1000);
d.toISOString(); // "2025-07-12T08:00:00.000Z"

// Date → timestamp(秒)
Math.floor(d.getTime() / 1000); // 1752307200

Python

from datetime import datetime, timezone

# timestamp(秒) → datetime
dt = datetime.fromtimestamp(1752307200, tz=timezone.utc)

# datetime → timestamp(秒)
int(dt.timestamp())

PHP

// timestamp(秒) → 日時文字列
echo date("Y-m-d H:i:s", 1752307200);

// 日時文字列 → timestamp(秒)
echo strtotime("2025-07-12 08:00:00");

Go

// timestamp(秒) → time.Time
t := time.Unix(1752307200, 0).UTC()

// time.Time → timestamp(秒)
sec := t.Unix()

Java

// timestamp(秒) → Instant
Instant instant = Instant.ofEpochSecond(1752307200L);

// Instant → timestamp(秒)
long sec = instant.getEpochSecond();

5. Unix timestampが使われる場面 / Where it shows up

まとめ / Summary

unix timestampは「1970-01-01 UTCからの経過秒数」という単一の整数で時刻を表す仕組みで、 タイムゾーンを持たない分、比較・保存・API連携が容易です。まずは桁数で秒/ミリ秒を見分け、 使用言語の標準関数で変換する、という基本フローを押さえれば十分です。タイムゾーン表示や 2038年問題などさらに踏み込んだ内容は関連ガイドをご覧ください。

A Unix timestamp is just seconds elapsed since 1970-01-01 UTC. Get the current one with a one-liner in your language, check digit count to tell seconds (10 digits) from milliseconds (13 digits), and convert with the standard library — no manual calendar math required. For timezone display pitfalls and the Y2038 rollover, see the deep-dive guide below.

Timestamp Converter

timestampと日時を両方向で即座に変換。桁数の入力ミスもその場で確認できます。

今すぐ試す →

関連ツール / Related tools

関連ガイド / Related guides