[{"data":1,"prerenderedAt":870},["ShallowReactive",2],{"guide-epoch-time-vs-iso-8601":3},{"id":4,"title":5,"body":6,"date":862,"description":863,"extension":864,"meta":865,"navigation":162,"path":866,"readingTime":166,"seo":867,"stem":868,"__hash__":869},"guides\u002Fguides\u002Fepoch-time-vs-iso-8601.md","Epoch Time vs ISO 8601: Key Differences and When to Use Each",{"type":7,"value":8,"toc":839},"minimark",[9,14,18,21,85,89,94,97,197,201,238,242,310,314,317,324,366,369,402,406,459,463,466,624,628,672,676,680,687,742,746,752,796,800,817,821,830,835],[10,11,13],"h2",{"id":12},"two-ways-to-represent-time","Two Ways to Represent Time",[15,16,17],"p",{},"Epoch time and ISO 8601 are the two dominant formats for representing dates and times in software. They serve different purposes, and choosing the wrong one creates interoperability headaches, timezone bugs, and debugging difficulties.",[15,19,20],{},"Epoch time (also called Unix time or POSIX time) counts the number of seconds since January 1, 1970, 00:00:00 UTC. ISO 8601 is a string format that represents dates and times in a human-readable, globally standardized way.",[22,23,28],"pre",{"className":24,"code":25,"language":26,"meta":27,"style":27},"language-javascript shiki shiki-themes github-light github-dark","\u002F\u002F Same moment, two representations\nconst epoch = 1716873600;                    \u002F\u002F Unix timestamp\nconst iso   = '2024-05-28T00:00:00Z';        \u002F\u002F ISO 8601 string\n","javascript","",[29,30,31,40,64],"code",{"__ignoreMap":27},[32,33,36],"span",{"class":34,"line":35},"line",1,[32,37,39],{"class":38},"sJ8bj","\u002F\u002F Same moment, two representations\n",[32,41,43,47,51,54,57,61],{"class":34,"line":42},2,[32,44,46],{"class":45},"szBVR","const",[32,48,50],{"class":49},"sj4cs"," epoch",[32,52,53],{"class":45}," =",[32,55,56],{"class":49}," 1716873600",[32,58,60],{"class":59},"sVt8B",";                    ",[32,62,63],{"class":38},"\u002F\u002F Unix timestamp\n",[32,65,67,69,72,75,79,82],{"class":34,"line":66},3,[32,68,46],{"class":45},[32,70,71],{"class":49}," iso",[32,73,74],{"class":45},"   =",[32,76,78],{"class":77},"sZZnC"," '2024-05-28T00:00:00Z'",[32,80,81],{"class":59},";        ",[32,83,84],{"class":38},"\u002F\u002F ISO 8601 string\n",[10,86,88],{"id":87},"epoch-time-compact-and-calculable","Epoch Time: Compact and Calculable",[90,91,93],"h3",{"id":92},"advantages","Advantages",[15,95,96],{},"Epoch timestamps are integers. This makes them trivial to compare, sort, subtract, and store:",[22,98,100],{"className":24,"code":99,"language":26,"meta":27,"style":27},"\u002F\u002F Time difference in seconds\nconst start = 1716873600;\nconst end   = 1716877200;\nconst elapsed = end - start; \u002F\u002F 3600 seconds = 1 hour\n\n\u002F\u002F Compare timestamps\nif (tokenExpireEpoch > currentEpoch) {\n  \u002F\u002F token still valid\n}\n",[29,101,102,107,121,135,157,164,170,185,191],{"__ignoreMap":27},[32,103,104],{"class":34,"line":35},[32,105,106],{"class":38},"\u002F\u002F Time difference in seconds\n",[32,108,109,111,114,116,118],{"class":34,"line":42},[32,110,46],{"class":45},[32,112,113],{"class":49}," start",[32,115,53],{"class":45},[32,117,56],{"class":49},[32,119,120],{"class":59},";\n",[32,122,123,125,128,130,133],{"class":34,"line":66},[32,124,46],{"class":45},[32,126,127],{"class":49}," end",[32,129,74],{"class":45},[32,131,132],{"class":49}," 1716877200",[32,134,120],{"class":59},[32,136,138,140,143,145,148,151,154],{"class":34,"line":137},4,[32,139,46],{"class":45},[32,141,142],{"class":49}," elapsed",[32,144,53],{"class":45},[32,146,147],{"class":59}," end ",[32,149,150],{"class":45},"-",[32,152,153],{"class":59}," start; ",[32,155,156],{"class":38},"\u002F\u002F 3600 seconds = 1 hour\n",[32,158,160],{"class":34,"line":159},5,[32,161,163],{"emptyLinePlaceholder":162},true,"\n",[32,165,167],{"class":34,"line":166},6,[32,168,169],{"class":38},"\u002F\u002F Compare timestamps\n",[32,171,173,176,179,182],{"class":34,"line":172},7,[32,174,175],{"class":45},"if",[32,177,178],{"class":59}," (tokenExpireEpoch ",[32,180,181],{"class":45},">",[32,183,184],{"class":59}," currentEpoch) {\n",[32,186,188],{"class":34,"line":187},8,[32,189,190],{"class":38},"  \u002F\u002F token still valid\n",[32,192,194],{"class":34,"line":193},9,[32,195,196],{"class":59},"}\n",[90,198,200],{"id":199},"limitations","Limitations",[202,203,204,216,222,228],"ul",{},[205,206,207,211,212,215],"li",{},[208,209,210],"strong",{},"Not human-readable",": ",[29,213,214],{},"1716873600"," tells you nothing without conversion",[205,217,218,221],{},[208,219,220],{},"Timezone-free by design",": Always UTC, which is an advantage for storage but requires conversion for display",[205,223,224,227],{},[208,225,226],{},"32-bit overflow",": Traditional 32-bit signed integers overflow on January 19, 2038 (the \"Year 2038 problem\")",[205,229,230,233,234,237],{},[208,231,232],{},"No sub-second precision in basic form",": Milliseconds require decimal notation (",[29,235,236],{},"1716873600.123",")",[90,239,241],{"id":240},"when-to-use-epoch","When to Use Epoch",[243,244,245,258],"table",{},[246,247,248],"thead",{},[249,250,251,255],"tr",{},[252,253,254],"th",{},"Scenario",[252,256,257],{},"Why Epoch Works",[259,260,261,270,286,294,302],"tbody",{},[249,262,263,267],{},[264,265,266],"td",{},"API rate-limit timestamps",[264,268,269],{},"Easy subtraction and comparison",[249,271,272,283],{},[264,273,274,275,278,279,282],{},"JWT ",[29,276,277],{},"exp"," and ",[29,280,281],{},"iat"," claims",[264,284,285],{},"Compact integer in token payload",[249,287,288,291],{},[264,289,290],{},"Log file timestamps",[264,292,293],{},"Fast to write and sort",[249,295,296,299],{},[264,297,298],{},"Cache expiration",[264,300,301],{},"Simple numeric comparison",[249,303,304,307],{},[264,305,306],{},"Database time columns (performance-critical)",[264,308,309],{},"Smaller storage, faster indexes",[10,311,313],{"id":312},"iso-8601-readable-and-unambiguous","ISO 8601: Readable and Unambiguous",[90,315,93],{"id":316},"advantages-1",[15,318,319,320,323],{},"ISO 8601 strings are self-documenting. A developer reading ",[29,321,322],{},"2024-05-28T14:30:00+02:00"," immediately understands the date, time, and timezone offset:",[22,325,327],{"className":24,"code":326,"language":26,"meta":27,"style":27},"\u002F\u002F ISO 8601 variants\n'2024-05-28'                    \u002F\u002F Date only\n'2024-05-28T14:30:00Z'          \u002F\u002F UTC time\n'2024-05-28T14:30:00+02:00'     \u002F\u002F Time with offset\n'2024-05-28T14:30:00.123Z'      \u002F\u002F With milliseconds\n",[29,328,329,334,342,350,358],{"__ignoreMap":27},[32,330,331],{"class":34,"line":35},[32,332,333],{"class":38},"\u002F\u002F ISO 8601 variants\n",[32,335,336,339],{"class":34,"line":42},[32,337,338],{"class":77},"'2024-05-28'",[32,340,341],{"class":38},"                    \u002F\u002F Date only\n",[32,343,344,347],{"class":34,"line":66},[32,345,346],{"class":77},"'2024-05-28T14:30:00Z'",[32,348,349],{"class":38},"          \u002F\u002F UTC time\n",[32,351,352,355],{"class":34,"line":137},[32,353,354],{"class":77},"'2024-05-28T14:30:00+02:00'",[32,356,357],{"class":38},"     \u002F\u002F Time with offset\n",[32,359,360,363],{"class":34,"line":159},[32,361,362],{"class":77},"'2024-05-28T14:30:00.123Z'",[32,364,365],{"class":38},"      \u002F\u002F With milliseconds\n",[90,367,200],{"id":368},"limitations-1",[202,370,371,377,383,389],{},[205,372,373,376],{},[208,374,375],{},"Larger storage",": 20-28 bytes vs 4-8 bytes for an integer",[205,378,379,382],{},[208,380,381],{},"Slower comparison",": String comparison works only when offsets are normalized to UTC",[205,384,385,388],{},[208,386,387],{},"Parsing overhead",": Requires a date library for reliable cross-browser parsing",[205,390,391,211,394,397,398,401],{},[208,392,393],{},"Timezone ambiguity without offset",[29,395,396],{},"2024-05-28T14:30:00"," without ",[29,399,400],{},"Z"," or offset is \"local time\" — interpreted differently depending on the runtime",[90,403,405],{"id":404},"when-to-use-iso-8601","When to Use ISO 8601",[243,407,408,417],{},[246,409,410],{},[249,411,412,414],{},[252,413,254],{},[252,415,416],{},"Why ISO 8601 Works",[259,418,419,427,435,443,451],{},[249,420,421,424],{},[264,422,423],{},"REST API request\u002Fresponse bodies",[264,425,426],{},"Human-readable, self-documenting",[249,428,429,432],{},[264,430,431],{},"Configuration files",[264,433,434],{},"Easy for humans to write and verify",[249,436,437,440],{},[264,438,439],{},"Database datetime columns",[264,441,442],{},"Better query readability",[249,444,445,448],{},[264,446,447],{},"Email headers and document metadata",[264,449,450],{},"Standardized and internationally understood",[249,452,453,456],{},[264,454,455],{},"Frontend display",[264,457,458],{},"Directly formattable for users",[10,460,462],{"id":461},"converting-between-formats","Converting Between Formats",[90,464,465],{"id":26},"JavaScript",[22,467,469],{"className":24,"code":468,"language":26,"meta":27,"style":27},"\u002F\u002F Epoch to ISO 8601\nconst iso = new Date(1716873600 * 1000).toISOString();\n\u002F\u002F \"2024-05-28T00:00:00.000Z\"\n\n\u002F\u002F ISO 8601 to Epoch\nconst epoch = Math.floor(new Date('2024-05-28T00:00:00Z').getTime() \u002F 1000);\n\u002F\u002F 1716873600\n\n\u002F\u002F Current time in both formats\nconst now = Date.now(); \u002F\u002F epoch milliseconds\nconst nowISO = new Date().toISOString();\n",[29,470,471,476,511,516,520,525,567,572,576,581,603],{"__ignoreMap":27},[32,472,473],{"class":34,"line":35},[32,474,475],{"class":38},"\u002F\u002F Epoch to ISO 8601\n",[32,477,478,480,482,484,487,491,494,496,499,502,505,508],{"class":34,"line":42},[32,479,46],{"class":45},[32,481,71],{"class":49},[32,483,53],{"class":45},[32,485,486],{"class":45}," new",[32,488,490],{"class":489},"sScJk"," Date",[32,492,493],{"class":59},"(",[32,495,214],{"class":49},[32,497,498],{"class":45}," *",[32,500,501],{"class":49}," 1000",[32,503,504],{"class":59},").",[32,506,507],{"class":489},"toISOString",[32,509,510],{"class":59},"();\n",[32,512,513],{"class":34,"line":66},[32,514,515],{"class":38},"\u002F\u002F \"2024-05-28T00:00:00.000Z\"\n",[32,517,518],{"class":34,"line":137},[32,519,163],{"emptyLinePlaceholder":162},[32,521,522],{"class":34,"line":159},[32,523,524],{"class":38},"\u002F\u002F ISO 8601 to Epoch\n",[32,526,527,529,531,533,536,539,541,544,546,548,551,553,556,559,562,564],{"class":34,"line":166},[32,528,46],{"class":45},[32,530,50],{"class":49},[32,532,53],{"class":45},[32,534,535],{"class":59}," Math.",[32,537,538],{"class":489},"floor",[32,540,493],{"class":59},[32,542,543],{"class":45},"new",[32,545,490],{"class":489},[32,547,493],{"class":59},[32,549,550],{"class":77},"'2024-05-28T00:00:00Z'",[32,552,504],{"class":59},[32,554,555],{"class":489},"getTime",[32,557,558],{"class":59},"() ",[32,560,561],{"class":45},"\u002F",[32,563,501],{"class":49},[32,565,566],{"class":59},");\n",[32,568,569],{"class":34,"line":172},[32,570,571],{"class":38},"\u002F\u002F 1716873600\n",[32,573,574],{"class":34,"line":187},[32,575,163],{"emptyLinePlaceholder":162},[32,577,578],{"class":34,"line":193},[32,579,580],{"class":38},"\u002F\u002F Current time in both formats\n",[32,582,584,586,589,591,594,597,600],{"class":34,"line":583},10,[32,585,46],{"class":45},[32,587,588],{"class":49}," now",[32,590,53],{"class":45},[32,592,593],{"class":59}," Date.",[32,595,596],{"class":489},"now",[32,598,599],{"class":59},"(); ",[32,601,602],{"class":38},"\u002F\u002F epoch milliseconds\n",[32,604,606,608,611,613,615,617,620,622],{"class":34,"line":605},11,[32,607,46],{"class":45},[32,609,610],{"class":49}," nowISO",[32,612,53],{"class":45},[32,614,486],{"class":45},[32,616,490],{"class":489},[32,618,619],{"class":59},"().",[32,621,507],{"class":489},[32,623,510],{"class":59},[90,625,627],{"id":626},"python","Python",[22,629,632],{"className":630,"code":631,"language":626,"meta":27,"style":27},"language-python shiki shiki-themes github-light github-dark","import datetime\n\n# Epoch to ISO 8601\ndt = datetime.datetime.fromtimestamp(1716873600, tz=datetime.timezone.utc)\niso = dt.isoformat()  # \"2024-05-28T00:00:00+00:00\"\n\n# ISO 8601 to Epoch\nepoch = int(dt.timestamp())  # 1716873600\n",[29,633,634,639,643,648,653,658,662,667],{"__ignoreMap":27},[32,635,636],{"class":34,"line":35},[32,637,638],{},"import datetime\n",[32,640,641],{"class":34,"line":42},[32,642,163],{"emptyLinePlaceholder":162},[32,644,645],{"class":34,"line":66},[32,646,647],{},"# Epoch to ISO 8601\n",[32,649,650],{"class":34,"line":137},[32,651,652],{},"dt = datetime.datetime.fromtimestamp(1716873600, tz=datetime.timezone.utc)\n",[32,654,655],{"class":34,"line":159},[32,656,657],{},"iso = dt.isoformat()  # \"2024-05-28T00:00:00+00:00\"\n",[32,659,660],{"class":34,"line":166},[32,661,163],{"emptyLinePlaceholder":162},[32,663,664],{"class":34,"line":172},[32,665,666],{},"# ISO 8601 to Epoch\n",[32,668,669],{"class":34,"line":187},[32,670,671],{},"epoch = int(dt.timestamp())  # 1716873600\n",[10,673,675],{"id":674},"common-pitfalls","Common Pitfalls",[90,677,679],{"id":678},"mixing-epoch-seconds-and-milliseconds","Mixing Epoch Seconds and Milliseconds",[15,681,682,683,686],{},"JavaScript's ",[29,684,685],{},"Date.now()"," returns milliseconds. Many APIs expect seconds. Off by a factor of 1000, your timestamps are either in 1970 or thousands of years in the future.",[22,688,690],{"className":24,"code":689,"language":26,"meta":27,"style":27},"\u002F\u002F Common bug\nconst ms = Date.now();          \u002F\u002F 1716873600000\nconst secs = Math.floor(ms \u002F 1000); \u002F\u002F 1716873600 — correct for APIs expecting seconds\n",[29,691,692,697,716],{"__ignoreMap":27},[32,693,694],{"class":34,"line":35},[32,695,696],{"class":38},"\u002F\u002F Common bug\n",[32,698,699,701,704,706,708,710,713],{"class":34,"line":42},[32,700,46],{"class":45},[32,702,703],{"class":49}," ms",[32,705,53],{"class":45},[32,707,593],{"class":59},[32,709,596],{"class":489},[32,711,712],{"class":59},"();          ",[32,714,715],{"class":38},"\u002F\u002F 1716873600000\n",[32,717,718,720,723,725,727,729,732,734,736,739],{"class":34,"line":66},[32,719,46],{"class":45},[32,721,722],{"class":49}," secs",[32,724,53],{"class":45},[32,726,535],{"class":59},[32,728,538],{"class":489},[32,730,731],{"class":59},"(ms ",[32,733,561],{"class":45},[32,735,501],{"class":49},[32,737,738],{"class":59},"); ",[32,740,741],{"class":38},"\u002F\u002F 1716873600 — correct for APIs expecting seconds\n",[90,743,745],{"id":744},"iso-8601-without-timezone","ISO 8601 Without Timezone",[15,747,748,749,751],{},"An ISO string without ",[29,750,400],{}," or an offset is treated as local time. This produces different results on servers in different timezones:",[22,753,755],{"className":24,"code":754,"language":26,"meta":27,"style":27},"\u002F\u002F Dangerous — interpreted as local time\nnew Date('2024-05-28T14:30:00');\n\n\u002F\u002F Safe — explicitly UTC\nnew Date('2024-05-28T14:30:00Z');\n",[29,756,757,762,775,779,784],{"__ignoreMap":27},[32,758,759],{"class":34,"line":35},[32,760,761],{"class":38},"\u002F\u002F Dangerous — interpreted as local time\n",[32,763,764,766,768,770,773],{"class":34,"line":42},[32,765,543],{"class":45},[32,767,490],{"class":489},[32,769,493],{"class":59},[32,771,772],{"class":77},"'2024-05-28T14:30:00'",[32,774,566],{"class":59},[32,776,777],{"class":34,"line":66},[32,778,163],{"emptyLinePlaceholder":162},[32,780,781],{"class":34,"line":137},[32,782,783],{"class":38},"\u002F\u002F Safe — explicitly UTC\n",[32,785,786,788,790,792,794],{"class":34,"line":159},[32,787,543],{"class":45},[32,789,490],{"class":489},[32,791,493],{"class":59},[32,793,346],{"class":77},[32,795,566],{"class":59},[10,797,799],{"id":798},"key-takeaways","Key Takeaways",[202,801,802,805,808,811,814],{},[205,803,804],{},"Epoch time is a compact integer representing seconds since 1970-01-01 UTC — ideal for computation and storage",[205,806,807],{},"ISO 8601 is a human-readable string — ideal for APIs, configuration, and display",[205,809,810],{},"Always include timezone information in ISO 8601 strings to avoid interpretation differences",[205,812,813],{},"Watch for the seconds vs milliseconds mismatch when working with Unix timestamps in JavaScript",[205,815,816],{},"Use epoch for JWT claims, log timestamps, and rate limiting; use ISO 8601 for API payloads and configuration",[10,818,820],{"id":819},"try-it-yourself","Try It Yourself",[15,822,823,824,829],{},"Convert between epoch time and ISO 8601 instantly with our free ",[825,826,828],"a",{"href":827},"\u002Ftools\u002Ftimestamp-converter","Timestamp Converter",". Enter any Unix timestamp to see its ISO 8601 equivalent, or paste an ISO string to get the epoch value — all processed locally in your browser.",[15,831,832],{},[825,833,834],{"href":827},"Try the Timestamp Converter →",[836,837,838],"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 .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}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);}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}",{"title":27,"searchDepth":42,"depth":42,"links":840},[841,842,847,852,856,860,861],{"id":12,"depth":42,"text":13},{"id":87,"depth":42,"text":88,"children":843},[844,845,846],{"id":92,"depth":66,"text":93},{"id":199,"depth":66,"text":200},{"id":240,"depth":66,"text":241},{"id":312,"depth":42,"text":313,"children":848},[849,850,851],{"id":316,"depth":66,"text":93},{"id":368,"depth":66,"text":200},{"id":404,"depth":66,"text":405},{"id":461,"depth":42,"text":462,"children":853},[854,855],{"id":26,"depth":66,"text":465},{"id":626,"depth":66,"text":627},{"id":674,"depth":42,"text":675,"children":857},[858,859],{"id":678,"depth":66,"text":679},{"id":744,"depth":66,"text":745},{"id":798,"depth":42,"text":799},{"id":819,"depth":42,"text":820},"2026-05-28","Compare Unix epoch time and ISO 8601 date formats. Learn when to use timestamps vs ISO strings in APIs, databases, and applications.","md",{"immutable":162},"\u002Fguides\u002Fepoch-time-vs-iso-8601",{"title":5,"description":863},"guides\u002Fepoch-time-vs-iso-8601","joUUKxhDxCTrGWLy9uE_HQ8F7CwsMZHSJoB9xaAEl0M",1780401333691]