Timestamp noi bat
Bang tra cuu dinh dang
| Dinh dang | Vi du |
|---|---|
| ISO 8601 | 2026-03-26T14:30:00Z API, co so du lieu, JSON, chuan quoc te |
| RFC 2822 | Thu, 26 Mar 2026 14:30:00 +0000 Header email, header HTTP |
| Unix Timestamp | 1774544200 Co so du lieu, log he thong, lap trinh |
| Doc duoc | 26 thang 3, 2026 14:30 Giao dien nguoi dung, bao cao |
| strftime %Y-%m-%d | 2026-03-26 Dinh dang ngay Python, Ruby, PHP |
| toLocaleDateString | 26/3/2026 JavaScript dinh dang theo locale |
Tra cuu mui gio
Unix Timestamp la gi?
Unix timestamp (con goi la Unix epoch time, POSIX time hoac Unix time) la mot he thong do thoi gian duoc su dung rong rai trong lap trinh va he thong may tinh. No bieu dien thoi gian bang so giay da troi ke tu ngay 1 thang 1 nam 1970, 00:00:00 UTC — thoi diem nay duoc goi la Unix Epoch. Vi du, timestamp 1700000000 tuong ung voi ngay 14 thang 11, 2023 luc 22:13:20 UTC.
Diem manh cua Unix timestamp la tinh don gian va nhat quan: no la mot so nguyen duy nhat, khong phu thuoc vao mui gio hay dinh dang ngay thang cua bat ky quoc gia nao. Dieu nay lam cho no tro thanh tieu chuan de facto de luu tru va truyen tai du lieu thoi gian trong co so du lieu, API, file log, va giao thuc mang. Hau het cac ngon ngu lap trinh deu co ham tich hop de chuyen doi giua timestamp va dinh dang ngay doc duoc cho con nguoi.
Cong cu nay giup ban chuyen doi giua Unix timestamp va cac dinh dang ngay thang pho bien nhu ISO 8601, RFC 2822 va dinh dang doc duoc. Tat ca xu ly dien ra tren trinh duyet cua ban — khong co du lieu nao duoc gui len may chu. Ban co the nhap timestamp theo giay (10 chu so) hoac mili giay (13 chu so), va cong cu se tu dong nhan dang.
Unix Epoch Time hoat dong nhu the nao
He thong dem thoi gian Unix bat dau tu thoi diem "zero" la 00:00:00 UTC ngay 1 thang 1 nam 1970. Moi giay sau thoi diem nay tang them 1 don vi. Vi du: luc 00:01:00 (1 phut sau Epoch) co timestamp la 60, 1 gio sau la 3600 (60 x 60), va 1 ngay sau la 86400 (24 x 60 x 60).
Cac thoi diem truoc Epoch duoc bieu dien bang so am. Vi du, ngay 31 thang 12 nam 1969 luc 23:59:59 UTC co timestamp la -1. Cac su kien lich su xa hon co the co timestamp am rat lon, vi du thoi diem Cach mang Phap (1789) co timestamp khoang -5706153600.
Leap seconds (giay nhuan) la mot diem dac biet: he thong Unix time khong tinh leap seconds — nghia la Unix time gia dinh moi ngay co dung 86400 giay. Khi mot giay nhuan duoc them vao, he dieu hanh xu ly no theo nhieu cach khac nhau (nhay giay, smear, hoac lap lai timestamp). Dieu nay co nghia la Unix timestamp khong hoan toan chinh xac den giay so voi thoi gian thien van, nhung sai lech nay chi la vai chuc giay sau hon 50 nam va khong anh huong den hau het ung dung.
Trong thuc te, hau het cac he thong su dung NTP (Network Time Protocol) de dong bo dong ho voi may chu thoi gian chinh xac, dam bao timestamp luan nhat quan giua cac may tinh va data center tren toan the gioi.
Cac dinh dang Timestamp giai thich
Co nhieu dinh dang bieu dien thoi gian khac nhau, moi dinh dang phuc vu mot muc dich cu the:
- Unix Timestamp: So nguyen (giay ke tu Epoch). Don gian, gon, ly tuong cho luu tru va tinh toan. Khong doc duoc truc tiep cho con nguoi.
- ISO 8601:
2026-03-26T14:30:00Z. Tieu chuan quoc te, duoc su dung trong API RESTful, JSON, va XML. Chu "Z" cuoi bieu thi UTC; offset nhu+07:00bieu thi mui gio cu the. - RFC 2822:
Thu, 26 Mar 2026 14:30:00 +0000. Chuan cho email header va HTTP header. Co ten ngay trong tuan, de doc nhung dai hon ISO 8601. - Timestamp mili giay: Unix timestamp nhan voi 1000. Duoc su dung trong JavaScript (
Date.now()), Java (System.currentTimeMillis()), va nhieu API hien dai. Co do chinh xac cao hon. - Dinh dang doc duoc: "March 26, 2026 2:30 PM" hoac "26 thang 3, 2026 14:30". Phu thuoc vao locale va mui gio, chi nen dung cho hien thi cho nguoi dung cuoi.
Khi thiet ke API hoac co so du lieu, luon luu tru thoi gian o UTC va chuyen doi sang mui gio dia phuong chi khi hien thi cho nguoi dung. Dieu nay tranh duoc cac loi phuc tap lien quan den DST (gio mua he) va chuyen doi mui gio.
Van de nam 2038 (Y2038 Problem)
Van de nam 2038, thuong goi la "Y2K38" hoac "Unix Millennium Bug", la mot loi tran so (integer overflow) se xay ra vao luc 03:14:07 UTC ngay 19 thang 1 nam 2038. Tai thoi diem nay, so giay ke tu Unix Epoch se dat den 2147483647 — gia tri lon nhat ma mot so nguyen co dau 32-bit co the luu tru.
Giay tiep theo (2147483648) se tran sang gia tri am tren he thong 32-bit, khien dong ho "quay lai" ngay 13 thang 12 nam 1901. Dieu nay co the gay ra sai lech nghiem trong trong cac he thong phu thuoc vao thoi gian: chung chi so, lich trinh backup, he thong tai chinh, va thiet bi IoT.
Giai phap: hau het cac he dieu hanh hien dai da chuyen sang so nguyen 64-bit de luu timestamp. So nguyen 64-bit co the bieu dien thoi gian den khoang 292 ty nam trong tuong lai — du xa cho moi muc dich su dung. Tuy nhien, nhieu he thong nhung (embedded systems), thiet bi IoT, va phan mem cu van su dung 32-bit va can duoc cap nhat truoc nam 2038.
Xem them cong cu lien quan: JSON Formatter, Base64 Encoder, va Cron Expression Generator.
Lam viec voi Timestamp trong code
Moi ngon ngu lap trinh deu co cach rieng de lam viec voi Unix timestamp. Duoi day la cac vi du pho bien:
JavaScript / TypeScript
// Lay timestamp hien tai (giay)
const now = Math.floor(Date.now() / 1000);
// Chuyen timestamp sang Date object
const date = new Date(timestamp * 1000);
// Chuyen Date sang timestamp
const ts = Math.floor(date.getTime() / 1000);
// Dinh dang theo mui gio
date.toLocaleString('vi-VN', { timeZone: 'Asia/Ho_Chi_Minh' });Python
import time
from datetime import datetime, timezone
# Timestamp hien tai
now = int(time.time())
# Timestamp sang datetime
dt = datetime.fromtimestamp(ts, tz=timezone.utc)
# Datetime sang timestamp
ts = int(dt.timestamp())PHP
// Timestamp hien tai
$now = time();
// Timestamp sang date string
$date = date('Y-m-d H:i:s', $timestamp);
// Date string sang timestamp
$ts = strtotime('2026-03-26 14:30:00');SQL (MySQL / PostgreSQL)
-- MySQL: timestamp sang datetime
SELECT FROM_UNIXTIME(1774544200);
-- PostgreSQL: timestamp sang datetime
SELECT to_timestamp(1774544200);
-- Ca hai: datetime sang timestamp
SELECT UNIX_TIMESTAMP('2026-03-26 14:30:00'); -- MySQL
SELECT EXTRACT(EPOCH FROM timestamp); -- PostgreSQLMeo quan trong: Luon su dung UTC khi luu tru timestamp trong co so du lieu. Chi chuyen doi sang mui gio dia phuong tai tang hien thi (frontend). Dieu nay giup tranh cac loi lien quan den DST va dam bao tinh nhat quan khi cac may chu nam o nhieu vung dia ly khac nhau.
Cau hoi thuong gap
Ban cung co the thich
JSON Formatter — Beautify, Minify & Validate JSON Online
Format, beautify, and minify JSON data with real-time validation. Configurable indentation (2/4/tab), instant error detection, copy and download. Free online JSON formatter for developers.
Base64 Encoder and Decoder — Encode & Decode Text Online
Encode text to Base64 or decode Base64 strings back to text instantly. Supports full UTF-8 for international characters and emoji. Free, private, runs entirely in your browser.
Diff Checker — Compare Two Text Blocks Side by Side Online
Compare two blocks of text side by side instantly. See added lines highlighted green, deleted lines red, and unchanged lines gray. Line numbers on both sides, ignore-whitespace toggle, case-insensitive option. Free, private, runs in your browser.
Them cong cu cho lap trinh vien
JSON Formatter — Beautify, Minify & Validate JSON Online
Format, beautify, and minify JSON data with real-time validation. Configurable indentation (2/4/tab), instant error detection, copy and download. Free online JSON formatter for developers.
JWT Decoder — Inspect JSON Web Tokens Online
Decode and inspect JSON Web Tokens instantly. View color-coded header, payload, and signature. Check token expiration, claims, and algorithm — all in your browser. Free, private, no data sent to any server.
Base64 Encoder and Decoder — Encode & Decode Text Online
Encode text to Base64 or decode Base64 strings back to text instantly. Supports full UTF-8 for international characters and emoji. Free, private, runs entirely in your browser.
URL Encoder and Decoder — Percent Encoding Tool Online
Encode text to URL-safe percent-encoding or decode percent-encoded strings instantly. Supports encodeURI, encodeURIComponent, and RFC 3986. Free, private, browser-based.
HTML Entity Encoder and Decoder — Escape HTML Characters Online
Encode special characters to HTML entities or decode entities back to text. Prevent XSS attacks and display code safely. Free, instant, browser-based.
Morse Code Translator — Encode & Decode Text to Morse Online
Convert text to Morse code or decode Morse back to text instantly. Hear audio playback with Web Audio API. Supports A-Z, 0-9, and punctuation. Free online translator.
Number Base Converter — Binary Hex Octal Decimal Base36 Online
Convert numbers between binary, octal, decimal, hex, and base36 instantly. Bit visualization, copy per row, custom base 2-36. Free online developer tool.
ROT13 Encoder and Decoder — Caesar Cipher Tool Online
Encode or decode text with ROT13 and ROT-N Caesar ciphers instantly. Adjustable rotation 1-25, visual cipher wheel, self-inverse. Free, private, browser-based.
Giới thiệu về Developer Tools
Công cụ developer tự động hóa các phần lặp đi lặp lại của công việc phần mềm: format JSON, encode/decode Base64, decode JWT để xác minh claim của token, tạo UUID, format XML, diff cấu hình. Đây không phải tác vụ hào nhoáng, nhưng là các điểm nghẽn ngốn 10-15 phút nhiều lần mỗi ngày — cộng lại hàng giờ mỗi tuần. Chạy chúng trên tab trình duyệt sạch sẽ hơn vật lộn với phụ thuộc CLI hay extension IDE có thể gửi dữ liệu riêng tư của bạn cho bên thứ ba.
Vì sao nó quan trọng
Công cụ developer client-side nhanh về cơ bản quan trọng vì chúng được dùng với dữ liệu nhạy cảm. JWT token chứa danh tính người dùng. Payload Base64 có thể encode API key. JSON dump bao gồm bản ghi khách hàng. Nếu một 'công cụ developer' gửi input của bạn lên server để xử lý, bạn vừa rò rỉ production secret. Công cụ dev của ZestLab chạy 100% client-side không có network call nào sau khi load page — những gì bạn paste vẫn ở trong trình duyệt.
Riêng tư và an toàn
Tất cả công cụ developer ở đây chạy trong trình duyệt bằng JavaScript thuần. Không có 'decode server' hay 'format API' — JWT, JSON, payload encode của bạn được parse bởi code chạy trên laptop của bạn. Tự xác minh bằng DevTools trình duyệt → Network tab: bạn sẽ thấy không có request nào khi dùng bất kỳ công cụ nào. Đó là tiêu chuẩn chúng tôi giữ vì công cụ dev xử lý secret.
Thực hành tốt
- Không bao giờ paste JWT hay API token production vào BẤT KỲ công cụ online nào mà không xác minh chạy client-side (check tab Network)
- Dùng chế độ ẩn danh trình duyệt để decode một lần các payload nhạy cảm
- Bookmark công cụ bạn dùng hàng ngày — URL công cụ ZestLab ổn định, không cần tài khoản
- Khi format JSON có secret để team review, redact credential trước khi share output