[{"data":1,"prerenderedAt":643},["ShallowReactive",2],{"guide-timestamp-formats-explained":3},{"id":4,"title":5,"body":6,"date":635,"description":636,"extension":637,"meta":638,"navigation":406,"path":639,"readingTime":478,"seo":640,"stem":641,"__hash__":642},"guides\u002Fguides\u002Ftimestamp-formats-explained.md","Timestamp Formats Compared: Unix, ISO 8601, RFC 3339",{"type":7,"value":8,"toc":619},"minimark",[9,14,18,41,44,48,51,62,67,81,86,97,100,103,109,113,127,131,145,148,151,157,161,175,179,187,191,313,317,334,337,341,346,442,446,493,497,535,539,578,582,603,607,615],[10,11,13],"h2",{"id":12},"why-timestamp-formats-matter","Why Timestamp Formats Matter",[15,16,17],"p",{},"Every application handles dates and times. Pick the wrong format, and you invite timezone bugs, parsing errors, and interoperability failures. Three formats dominate modern development:",[19,20,21,29,35],"ul",{},[22,23,24,28],"li",{},[25,26,27],"strong",{},"Unix timestamp"," — a single integer",[22,30,31,34],{},[25,32,33],{},"ISO 8601"," — a structured string standard",[22,36,37,40],{},[25,38,39],{},"RFC 3339"," — an internet-friendly profile of ISO 8601",[15,42,43],{},"Each serves a different purpose. Here is how they compare.",[10,45,47],{"id":46},"unix-timestamp","Unix Timestamp",[15,49,50],{},"A Unix timestamp counts seconds (or milliseconds) since January 1, 1970, 00:00:00 UTC.",[52,53,59],"pre",{"className":54,"code":56,"language":57,"meta":58},[55],"language-text","1748300000\n","text","",[60,61,56],"code",{"__ignoreMap":58},[15,63,64],{},[25,65,66],{},"Strengths:",[19,68,69,72,75,78],{},[22,70,71],{},"One integer — trivial to store, sort, and compare",[22,73,74],{},"Always UTC — no timezone ambiguity",[22,76,77],{},"Compact — minimal storage and bandwidth",[22,79,80],{},"Language-neutral — every language can handle an integer",[15,82,83],{},[25,84,85],{},"Weaknesses:",[19,87,88,91,94],{},[22,89,90],{},"Not human-readable",[22,92,93],{},"Seconds vs milliseconds can cause confusion",[22,95,96],{},"Loses sub-second precision unless you use decimals or milliseconds",[10,98,33],{"id":99},"iso-8601",[15,101,102],{},"ISO 8601 is an international standard for date and time formatting. It defines a hierarchy of representations from dates to durations.",[52,104,107],{"className":105,"code":106,"language":57,"meta":58},[55],"2025-05-26T20:53:20Z          (UTC)\n2025-05-26T16:53:20-04:00     (with offset)\n2025-05-26                    (date only)\nP1Y2M3D                       (duration)\n",[60,108,106],{"__ignoreMap":58},[15,110,111],{},[25,112,66],{},[19,114,115,118,121,124],{},[22,116,117],{},"Human-readable — clear and unambiguous",[22,119,120],{},"Sortable — alphabetical order matches chronological order",[22,122,123],{},"Flexible — supports dates, times, ranges, and durations",[22,125,126],{},"Widely adopted — used in JSON APIs, XML, and logs",[15,128,129],{},[25,130,85],{},[19,132,133,136,139,142],{},[22,134,135],{},"String comparison works only for the same timezone offset",[22,137,138],{},"Larger storage than an integer",[22,140,141],{},"Many valid variations (with or without dashes, colons, T separator)",[22,143,144],{},"Parsing must handle optional components",[10,146,39],{"id":147},"rfc-3339",[15,149,150],{},"RFC 3339 is a strict subset of ISO 8601 designed for internet protocols. It removes ambiguous ISO 8601 features to keep parsing simple.",[52,152,155],{"className":153,"code":154,"language":57,"meta":58},[55],"2025-05-26T20:53:20Z\n2025-05-26T16:53:20-04:00\n",[60,156,154],{"__ignoreMap":58},[15,158,159],{},[25,160,66],{},[19,162,163,166,169,172],{},[22,164,165],{},"Compatible with ISO 8601",[22,167,168],{},"Strict rules — easier to parse correctly",[22,170,171],{},"Required by many internet standards (HTTP, SMTP, Atom feeds)",[22,173,174],{},"Always includes full date and time — no partial representations",[15,176,177],{},[25,178,85],{},[19,180,181,184],{},[22,182,183],{},"Does not support durations, intervals, or date-only forms",[22,185,186],{},"Slightly less flexible than full ISO 8601",[10,188,190],{"id":189},"format-comparison","Format Comparison",[192,193,194,210],"table",{},[195,196,197],"thead",{},[198,199,200,204,206,208],"tr",{},[201,202,203],"th",{},"Feature",[201,205,47],{},[201,207,33],{},[201,209,39],{},[211,212,213,227,240,254,266,279,291,302],"tbody",{},[198,214,215,219,222,225],{},[216,217,218],"td",{},"Type",[216,220,221],{},"Integer",[216,223,224],{},"String",[216,226,224],{},[198,228,229,232,235,238],{},[216,230,231],{},"Human-readable",[216,233,234],{},"No",[216,236,237],{},"Yes",[216,239,237],{},[198,241,242,245,248,251],{},[216,243,244],{},"Timezone info",[216,246,247],{},"Always UTC",[216,249,250],{},"Optional",[216,252,253],{},"Required",[198,255,256,259,261,264],{},[216,257,258],{},"Sortable",[216,260,237],{},[216,262,263],{},"Alphabetically",[216,265,263],{},[198,267,268,271,274,277],{},[216,269,270],{},"Storage size",[216,272,273],{},"4–8 bytes",[216,275,276],{},"20–28 bytes",[216,278,276],{},[198,280,281,284,287,289],{},[216,282,283],{},"Sub-second precision",[216,285,286],{},"Milliseconds optional",[216,288,237],{},[216,290,237],{},[198,292,293,296,298,300],{},[216,294,295],{},"Date-only support",[216,297,234],{},[216,299,237],{},[216,301,234],{},[198,303,304,307,309,311],{},[216,305,306],{},"Duration support",[216,308,234],{},[216,310,237],{},[216,312,234],{},[10,314,316],{"id":315},"when-to-use-each-format","When to Use Each Format",[19,318,319,324,329],{},[22,320,321,323],{},[25,322,27],{}," — databases, cache keys, log entries, performance-critical code, TTL calculations",[22,325,326,328],{},[25,327,33],{}," — API responses, configuration files, data exchange, when humans need to read values",[22,330,331,333],{},[25,332,39],{}," — HTTP headers, email dates, API contracts that need strict parsing rules",[15,335,336],{},"A common pattern: store timestamps as Unix integers internally, display them as ISO 8601 \u002F RFC 3339 strings in APIs and user interfaces.",[10,338,340],{"id":339},"examples-by-language","Examples by Language",[342,343,345],"h3",{"id":344},"javascript","JavaScript",[52,347,350],{"className":348,"code":349,"language":344,"meta":58,"style":58},"language-javascript shiki shiki-themes github-light github-dark","\u002F\u002F Current Unix timestamp\nconst ts = Math.floor(Date.now() \u002F 1000)\n\n\u002F\u002F To ISO 8601\nnew Date(ts * 1000).toISOString() \u002F\u002F \"2025-05-26T20:53:20.000Z\"\n",[60,351,352,361,401,408,414],{"__ignoreMap":58},[353,354,357],"span",{"class":355,"line":356},"line",1,[353,358,360],{"class":359},"sJ8bj","\u002F\u002F Current Unix timestamp\n",[353,362,364,368,372,375,379,383,386,389,392,395,398],{"class":355,"line":363},2,[353,365,367],{"class":366},"szBVR","const",[353,369,371],{"class":370},"sj4cs"," ts",[353,373,374],{"class":366}," =",[353,376,378],{"class":377},"sVt8B"," Math.",[353,380,382],{"class":381},"sScJk","floor",[353,384,385],{"class":377},"(Date.",[353,387,388],{"class":381},"now",[353,390,391],{"class":377},"() ",[353,393,394],{"class":366},"\u002F",[353,396,397],{"class":370}," 1000",[353,399,400],{"class":377},")\n",[353,402,404],{"class":355,"line":403},3,[353,405,407],{"emptyLinePlaceholder":406},true,"\n",[353,409,411],{"class":355,"line":410},4,[353,412,413],{"class":359},"\u002F\u002F To ISO 8601\n",[353,415,417,420,423,426,429,431,434,437,439],{"class":355,"line":416},5,[353,418,419],{"class":366},"new",[353,421,422],{"class":381}," Date",[353,424,425],{"class":377},"(ts ",[353,427,428],{"class":366},"*",[353,430,397],{"class":370},[353,432,433],{"class":377},").",[353,435,436],{"class":381},"toISOString",[353,438,391],{"class":377},[353,440,441],{"class":359},"\u002F\u002F \"2025-05-26T20:53:20.000Z\"\n",[342,443,445],{"id":444},"python","Python",[52,447,450],{"className":448,"code":449,"language":444,"meta":58,"style":58},"language-python shiki shiki-themes github-light github-dark","import time\nfrom datetime import datetime, timezone\n\n# Current Unix timestamp\nts = int(time.time())\n\n# To ISO 8601\ndatetime.fromtimestamp(ts, tz=timezone.utc).isoformat()  # \"2025-05-26T20:53:20+00:00\"\n",[60,451,452,457,462,466,471,476,481,487],{"__ignoreMap":58},[353,453,454],{"class":355,"line":356},[353,455,456],{},"import time\n",[353,458,459],{"class":355,"line":363},[353,460,461],{},"from datetime import datetime, timezone\n",[353,463,464],{"class":355,"line":403},[353,465,407],{"emptyLinePlaceholder":406},[353,467,468],{"class":355,"line":410},[353,469,470],{},"# Current Unix timestamp\n",[353,472,473],{"class":355,"line":416},[353,474,475],{},"ts = int(time.time())\n",[353,477,479],{"class":355,"line":478},6,[353,480,407],{"emptyLinePlaceholder":406},[353,482,484],{"class":355,"line":483},7,[353,485,486],{},"# To ISO 8601\n",[353,488,490],{"class":355,"line":489},8,[353,491,492],{},"datetime.fromtimestamp(ts, tz=timezone.utc).isoformat()  # \"2025-05-26T20:53:20+00:00\"\n",[342,494,496],{"id":495},"go","Go",[52,498,501],{"className":499,"code":500,"language":495,"meta":58,"style":58},"language-go shiki shiki-themes github-light github-dark","import \"time\"\n\n\u002F\u002F Current Unix timestamp\nts := time.Now().Unix()\n\n\u002F\u002F To RFC 3339\ntime.Unix(ts, 0).UTC().Format(time.RFC3339) \u002F\u002F \"2025-05-26T20:53:20Z\"\n",[60,502,503,508,512,516,521,525,530],{"__ignoreMap":58},[353,504,505],{"class":355,"line":356},[353,506,507],{},"import \"time\"\n",[353,509,510],{"class":355,"line":363},[353,511,407],{"emptyLinePlaceholder":406},[353,513,514],{"class":355,"line":403},[353,515,360],{},[353,517,518],{"class":355,"line":410},[353,519,520],{},"ts := time.Now().Unix()\n",[353,522,523],{"class":355,"line":416},[353,524,407],{"emptyLinePlaceholder":406},[353,526,527],{"class":355,"line":478},[353,528,529],{},"\u002F\u002F To RFC 3339\n",[353,531,532],{"class":355,"line":483},[353,533,534],{},"time.Unix(ts, 0).UTC().Format(time.RFC3339) \u002F\u002F \"2025-05-26T20:53:20Z\"\n",[10,536,538],{"id":537},"timezone-handling-tips","Timezone Handling Tips",[19,540,541,547,561,567],{},[22,542,543,546],{},[25,544,545],{},"Never"," store local times in databases — always use UTC",[22,548,549,552,553,556,557,560],{},[25,550,551],{},"Always"," include timezone offsets in string formats (",[60,554,555],{},"Z"," or ",[60,558,559],{},"+00:00",")",[22,562,563,564],{},"Convert to the user's local timezone ",[25,565,566],{},"only at display time",[22,568,569,570,573,574,577],{},"Be explicit: ",[60,571,572],{},"2025-05-26T20:53:20"," is ambiguous; ",[60,575,576],{},"2025-05-26T20:53:20Z"," is not",[10,579,581],{"id":580},"related-guides","Related Guides",[19,583,584,591,597],{},[22,585,586],{},[587,588,590],"a",{"href":589},"\u002Fguides\u002Funix-timestamp-guide","Unix Timestamp Explained",[22,592,593],{},[587,594,596],{"href":595},"\u002Fguides\u002Fdatetime-programming-tips","DateTime Programming Tips",[22,598,599],{},[587,600,602],{"href":601},"\u002Fguides\u002Fsystemd-timers-vs-cron","systemd vs Cron",[10,604,606],{"id":605},"try-it-yourself","Try It Yourself",[15,608,609,610,614],{},"Use our free ",[587,611,613],{"href":612},"\u002Ftools\u002Ftimestamp-converter","Timestamp Converter"," to convert between Unix timestamps and human-readable formats instantly.",[616,617,618],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":58,"searchDepth":363,"depth":363,"links":620},[621,622,623,624,625,626,627,632,633,634],{"id":12,"depth":363,"text":13},{"id":46,"depth":363,"text":47},{"id":99,"depth":363,"text":33},{"id":147,"depth":363,"text":39},{"id":189,"depth":363,"text":190},{"id":315,"depth":363,"text":316},{"id":339,"depth":363,"text":340,"children":628},[629,630,631],{"id":344,"depth":403,"text":345},{"id":444,"depth":403,"text":445},{"id":495,"depth":403,"text":496},{"id":537,"depth":363,"text":538},{"id":580,"depth":363,"text":581},{"id":605,"depth":363,"text":606},"2026-05-27","Compare Unix timestamps, ISO 8601, and RFC 3339 date formats. Learn when to use each format in your applications.","md",{"immutable":406},"\u002Fguides\u002Ftimestamp-formats-explained",{"title":5,"description":636},"guides\u002Ftimestamp-formats-explained","-ubDeUzVaEwJMPvUtAERY36M8KlmNUbid8l8cxAkdQY",1780401325570]