Unixタイムスタンプコンバーター
Unixタイムスタンプ(エポック時間)を読みやすい日付に変換、または逆変換。 秒とミリ秒対応。全タイムゾーン対応。 開発者とシステム管理者の必須ツール。
Unix Time Converter
How to use:
- Enter a Unix timestamp to convert it to human-readable date
- Select a date and time to convert it to Unix timestamp
- Unix time is the number of seconds since January 1, 1970 (UTC)
なぜUnixタイムスタンプを使うのか?
Unixタイムスタンプはプログラミングとシステム操作の基礎
プログラミング・開発
Unixタイムスタンプは言語に依存しない。データベース、API、ログで日付を整数として保存。タイムゾーンの曖昧さなし—常にUTC基準。
データベースストレージ
タイムスタンプを日時文字列(20+バイト)ではなく整数(4または8バイト)で保存。インデックスとクエリが高速化。
API統合
REST APIはcreated_at、updated_at、expires_atフィールドにUnixタイムスタンプをよく使用。日付形式の曖昧さなし。
ログ分析
サーバーログ、アプリケーションログ、システムログはUnixタイムスタンプをよく使用。時系列ソートが容易。
スケジューリング・タイマー
cronジョブ、スケジュールタスク、タイマーはUnix時間を使用。夏時間の変更は自動処理。
セキュリティ・有効期限
セッション有効期限、トークン有効性、キャッシュTTLはすべてUnixタイムスタンプを使用。SSL証明書、署名付きURL、一時アクセスコードに使用。
Unixタイムスタンプを理解する
Unix時間とは?
Unix時間(エポック時間、POSIX時間とも)は1970年1月1日00:00:00 UTC(Unixエポック)からの経過秒数。
例:
0= January 1, 1970, 00:00:00 UTC1000000000= September 9, 2001, 01:46:40 UTC1700000000= November 14, 2023, 22:13:20 UTC
秒とミリ秒
Unixタイムスタンプ(秒):10桁。ほとんどのUnixシステムの標準。
Unixタイムスタンプ(ミリ秒):13桁。JavaScriptで使用。
変換: 秒×1000でミリ秒。ミリ秒÷1000で秒。
なぜ1970年?
Unixは1960年代後半に開発。作成者は実用的な理由で1970年1月1日をエポックに選択:
- Unix開発時期に近い
- 整数年(1970)から始まりシンプルで覚えやすい
- 事実上の標準になった
- 負のタイムスタンプは1970年より前の日付を表す
2038年問題
32ビットシステムは最大2,147,483,647秒のタイムスタンプしか保存できない(2038年1月19日03:14:07 UTC)。その後、32ビットタイムスタンプはオーバーフロー。
解決策: 現代のシステムは64ビットタイムスタンプを使用し、範囲を2920億年に拡張。
コードでのUnixタイムスタンプ
JavaScript / TypeScript
// Get current Unix timestamp (milliseconds)
const now = Date.now(); // 1700000000000
// Get current Unix timestamp (seconds)
const nowSeconds = Math.floor(Date.now() / 1000); // 1700000000
// Convert timestamp to Date
const date = new Date(1700000000 * 1000);
console.log(date.toISOString()); // "2023-11-14T22:13:20.000Z"
// Convert Date to timestamp
const timestamp = Math.floor(new Date('2023-11-14').getTime() / 1000);
// Format human-readable
const readable = new Date(1700000000 * 1000).toLocaleString();
console.log(readable); // "11/14/2023, 10:13:20 PM"Python
import time
from datetime import datetime
# Get current Unix timestamp
now = time.time() # 1700000000.123
# Convert timestamp to datetime
dt = datetime.fromtimestamp(1700000000)
print(dt) # 2023-11-14 22:13:20
# Convert datetime to timestamp
timestamp = datetime(2023, 11, 14).timestamp()
# Format human-readable
readable = datetime.fromtimestamp(1700000000).strftime('%Y-%m-%d %H:%M:%S')
print(readable) # "2023-11-14 22:13:20"PHP
// Get current Unix timestamp
$now = time(); // 1700000000
// Convert timestamp to date
$date = date('Y-m-d H:i:s', 1700000000);
echo $date; // "2023-11-14 22:13:20"
// Convert date to timestamp
$timestamp = strtotime('2023-11-14 22:13:20');
// Using DateTime
$dt = new DateTime('@1700000000');
echo $dt->format('Y-m-d H:i:s'); // "2023-11-14 22:13:20"MySQL / SQL
-- Convert timestamp to datetime
SELECT FROM_UNIXTIME(1700000000);
-- Result: '2023-11-14 22:13:20'
-- Convert datetime to timestamp
SELECT UNIX_TIMESTAMP('2023-11-14 22:13:20');
-- Result: 1700000000
-- Get current timestamp
SELECT UNIX_TIMESTAMP();
-- Query with timestamp
SELECT * FROM logs
WHERE created_at > 1700000000;よくある質問
Unixタイムスタンプとは?
Unixタイムスタンプは1970年1月1日00:00:00 UTC(Unixエポック)からの経過秒数(またはミリ秒数)。タイムゾーンに依存しない特定の瞬間を表すシンプルな整数。
なぜUnixタイムスタンプを使う?
Unixタイムスタンプは言語非依存、タイムゾーン非依存、比較・ソートが容易、ストレージがコンパクト、算術演算が便利。
秒とミリ秒の違いは?
秒単位のUnixタイムスタンプは10桁(例:1700000000)。ミリ秒は13桁(例:1700000000000)でより高精度。JavaScriptはデフォルトでミリ秒を使用。
現在のUnixタイムスタンプを取得するには?
JavaScript: Math.floor(Date.now() / 1000)。Python: time.time()。PHP: time()。Bash: date +%s。
Unixタイムスタンプは1970年より前を表せる?
はい!負のUnixタイムスタンプは1970年1月1日より前の日付を表す。例:-86400は1969年12月31日。
Unixタイムスタンプのタイムゾーンをどう扱う?
Unixタイムスタンプは常にUTC。人間が読める形式に変換する際にタイムゾーンを指定。UTCで保存し、表示時にローカルタイムゾーンに変換。