[{"data":1,"prerenderedAt":563},["ShallowReactive",2],{"guide-unix-timestamp-guide":3},{"id":4,"title":5,"body":6,"date":555,"description":556,"extension":557,"meta":558,"navigation":380,"path":559,"readingTime":390,"seo":560,"stem":561,"__hash__":562},"guides\u002Fguides\u002Funix-timestamp-guide.md","Unix Timestamp Explained: How Epoch Time Works",{"type":7,"value":8,"toc":542},"minimark",[9,14,23,34,37,41,56,105,110,120,193,215,219,230,236,243,246,250,290,294,299,317,320,324,415,460,464,501,505,526,530,538],[10,11,13],"h2",{"id":12},"what-is-a-unix-timestamp","What Is a Unix Timestamp?",[15,16,17,18,22],"p",{},"A Unix timestamp counts the number of seconds elapsed since January 1, 1970, 00:00:00 UTC — known as the ",[19,20,21],"strong",{},"Unix epoch",". Developers call it epoch time, POSIX time, or Unix time.",[24,25,31],"pre",{"className":26,"code":28,"language":29,"meta":30},[27],"language-text","Unix epoch: 1970-01-01 00:00:00 UTC → Timestamp 0\nCurrent time (example): 1748300000\n","text","",[32,33,28],"code",{"__ignoreMap":30},[15,35,36],{},"The format is simple: one integer, always UTC, no time zones, no formatting ambiguity. That simplicity makes timestamps the backbone of modern software.",[10,38,40],{"id":39},"seconds-vs-milliseconds","Seconds vs Milliseconds",[15,42,43,44,47,48,51,52,55],{},"Most systems store timestamps in ",[19,45,46],{},"seconds",". JavaScript's ",[32,49,50],{},"Date.now()"," returns ",[19,53,54],{},"milliseconds"," instead.",[57,58,59,75],"table",{},[60,61,62],"thead",{},[63,64,65,69,72],"tr",{},[66,67,68],"th",{},"Format",[66,70,71],{},"Example",[66,73,74],{},"Used By",[76,77,78,92],"tbody",{},[63,79,80,84,89],{},[81,82,83],"td",{},"Seconds",[81,85,86],{},[32,87,88],{},"1748300000",[81,90,91],{},"Unix, Linux, databases, APIs",[63,93,94,97,102],{},[81,95,96],{},"Milliseconds",[81,98,99],{},[32,100,101],{},"1748300000000",[81,103,104],{},"JavaScript, Java, Go",[15,106,107],{},[19,108,109],{},"Conversion is straightforward:",[111,112,113,117],"ul",{},[114,115,116],"li",{},"Seconds → Milliseconds: multiply by 1000",[114,118,119],{},"Milliseconds → Seconds: divide by 1000 (truncate decimals)",[24,121,125],{"className":122,"code":123,"language":124,"meta":30,"style":30},"language-javascript shiki shiki-themes github-light github-dark","\u002F\u002F JavaScript: convert seconds to a Date object\nconst date = new Date(1748300000 * 1000)\nconsole.log(date.toUTCString()) \u002F\u002F \"Mon, 26 May 2025 20:53:20 GMT\"\n","javascript",[32,126,127,136,172],{"__ignoreMap":30},[128,129,132],"span",{"class":130,"line":131},"line",1,[128,133,135],{"class":134},"sJ8bj","\u002F\u002F JavaScript: convert seconds to a Date object\n",[128,137,139,143,147,150,153,157,161,163,166,169],{"class":130,"line":138},2,[128,140,142],{"class":141},"szBVR","const",[128,144,146],{"class":145},"sj4cs"," date",[128,148,149],{"class":141}," =",[128,151,152],{"class":141}," new",[128,154,156],{"class":155},"sScJk"," Date",[128,158,160],{"class":159},"sVt8B","(",[128,162,88],{"class":145},[128,164,165],{"class":141}," *",[128,167,168],{"class":145}," 1000",[128,170,171],{"class":159},")\n",[128,173,175,178,181,184,187,190],{"class":130,"line":174},3,[128,176,177],{"class":159},"console.",[128,179,180],{"class":155},"log",[128,182,183],{"class":159},"(date.",[128,185,186],{"class":155},"toUTCString",[128,188,189],{"class":159},"()) ",[128,191,192],{"class":134},"\u002F\u002F \"Mon, 26 May 2025 20:53:20 GMT\"\n",[24,194,198],{"className":195,"code":196,"language":197,"meta":30,"style":30},"language-python shiki shiki-themes github-light github-dark","# Python: current Unix timestamp in seconds\nimport time\nprint(int(time.time()))  # e.g., 1748300000\n","python",[32,199,200,205,210],{"__ignoreMap":30},[128,201,202],{"class":130,"line":131},[128,203,204],{},"# Python: current Unix timestamp in seconds\n",[128,206,207],{"class":130,"line":138},[128,208,209],{},"import time\n",[128,211,212],{"class":130,"line":174},[128,213,214],{},"print(int(time.time()))  # e.g., 1748300000\n",[10,216,218],{"id":217},"the-year-2038-problem","The Year 2038 Problem",[15,220,221,222,225,226,229],{},"Early Unix systems stored timestamps in a ",[19,223,224],{},"signed 32-bit integer",", which maxes out at ",[32,227,228],{},"2,147,483,647",".",[24,231,234],{"className":232,"code":233,"language":29,"meta":30},[27],"Max 32-bit timestamp: 2147483647\nDate: 2038-01-19 03:14:07 UTC\n",[32,235,233],{"__ignoreMap":30},[15,237,238,239,242],{},"After that moment, a 32-bit counter ",[19,240,241],{},"rolls over to a negative number",", causing bugs similar to the Y2K issue. The fix? Use 64-bit integers, which support timestamps up to year 292 billion — effectively forever.",[15,244,245],{},"Most modern systems and languages already use 64-bit storage, but legacy embedded systems and older file formats may still be vulnerable.",[10,247,249],{"id":248},"common-use-cases","Common Use Cases",[111,251,252,266,272,278,284],{},[114,253,254,257,258,261,262,265],{},[19,255,256],{},"Databases",": Store ",[32,259,260],{},"created_at"," and ",[32,263,264],{},"updated_at"," as integers for fast sorting and indexing",[114,267,268,271],{},[19,269,270],{},"APIs",": Pass timestamps in JSON payloads to avoid timezone parsing issues",[114,273,274,277],{},[19,275,276],{},"Caching",": Use timestamps for cache invalidation and TTL calculations",[114,279,280,283],{},[19,281,282],{},"Logging",": Record events with precise, sortable timestamps",[114,285,286,289],{},[19,287,288],{},"Scheduling",": Cron jobs and task schedulers rely on epoch time internally",[10,291,293],{"id":292},"converting-timestamps","Converting Timestamps",[295,296,298],"h3",{"id":297},"by-hand","By Hand",[300,301,302,308,311,314],"ol",{},[114,303,304,305,307],{},"Take the timestamp value (e.g., ",[32,306,88],{},")",[114,309,310],{},"Divide by 86400 to get days since epoch",[114,312,313],{},"Add those days to January 1, 1970",[114,315,316],{},"Account for leap years",[15,318,319],{},"In practice, use a programming language or online converter instead.",[295,321,323],{"id":322},"in-code","In Code",[24,325,327],{"className":122,"code":326,"language":124,"meta":30,"style":30},"\u002F\u002F Get current timestamp\nDate.now()                    \u002F\u002F milliseconds\nMath.floor(Date.now() \u002F 1000) \u002F\u002F seconds\n\n\u002F\u002F Timestamp to human-readable\nnew Date(1748300000 * 1000).toISOString() \u002F\u002F \"2025-05-26T20:53:20.000Z\"\n",[32,328,329,334,348,375,382,388],{"__ignoreMap":30},[128,330,331],{"class":130,"line":131},[128,332,333],{"class":134},"\u002F\u002F Get current timestamp\n",[128,335,336,339,342,345],{"class":130,"line":138},[128,337,338],{"class":159},"Date.",[128,340,341],{"class":155},"now",[128,343,344],{"class":159},"()                    ",[128,346,347],{"class":134},"\u002F\u002F milliseconds\n",[128,349,350,353,356,359,361,364,367,369,372],{"class":130,"line":174},[128,351,352],{"class":159},"Math.",[128,354,355],{"class":155},"floor",[128,357,358],{"class":159},"(Date.",[128,360,341],{"class":155},[128,362,363],{"class":159},"() ",[128,365,366],{"class":141},"\u002F",[128,368,168],{"class":145},[128,370,371],{"class":159},") ",[128,373,374],{"class":134},"\u002F\u002F seconds\n",[128,376,378],{"class":130,"line":377},4,[128,379,381],{"emptyLinePlaceholder":380},true,"\n",[128,383,385],{"class":130,"line":384},5,[128,386,387],{"class":134},"\u002F\u002F Timestamp to human-readable\n",[128,389,391,394,396,398,400,402,404,407,410,412],{"class":130,"line":390},6,[128,392,393],{"class":141},"new",[128,395,156],{"class":155},[128,397,160],{"class":159},[128,399,88],{"class":145},[128,401,165],{"class":141},[128,403,168],{"class":145},[128,405,406],{"class":159},").",[128,408,409],{"class":155},"toISOString",[128,411,363],{"class":159},[128,413,414],{"class":134},"\u002F\u002F \"2025-05-26T20:53:20.000Z\"\n",[24,416,418],{"className":195,"code":417,"language":197,"meta":30,"style":30},"# Get current timestamp\nimport time\ntime.time()          # float, seconds\nint(time.time())     # int, seconds\n\n# Timestamp to human-readable\nfrom datetime import datetime\ndatetime.utcfromtimestamp(1748300000).isoformat()  # \"2025-05-26T20:53:20+00:00\"\n",[32,419,420,425,429,434,439,443,448,454],{"__ignoreMap":30},[128,421,422],{"class":130,"line":131},[128,423,424],{},"# Get current timestamp\n",[128,426,427],{"class":130,"line":138},[128,428,209],{},[128,430,431],{"class":130,"line":174},[128,432,433],{},"time.time()          # float, seconds\n",[128,435,436],{"class":130,"line":377},[128,437,438],{},"int(time.time())     # int, seconds\n",[128,440,441],{"class":130,"line":384},[128,442,381],{"emptyLinePlaceholder":380},[128,444,445],{"class":130,"line":390},[128,446,447],{},"# Timestamp to human-readable\n",[128,449,451],{"class":130,"line":450},7,[128,452,453],{},"from datetime import datetime\n",[128,455,457],{"class":130,"line":456},8,[128,458,459],{},"datetime.utcfromtimestamp(1748300000).isoformat()  # \"2025-05-26T20:53:20+00:00\"\n",[10,461,463],{"id":462},"key-facts-to-remember","Key Facts to Remember",[111,465,466,473,480,486,494],{},[114,467,468,469,472],{},"Unix timestamps are ",[19,470,471],{},"always UTC"," — no time zone offsets",[114,474,475,476,479],{},"They ",[19,477,478],{},"ignore leap seconds"," — each day is exactly 86400 seconds",[114,481,482,483],{},"Negative timestamps represent dates ",[19,484,485],{},"before 1970",[114,487,488,489,491,492],{},"JavaScript uses ",[19,490,54],{},"; most everything else uses ",[19,493,46],{},[114,495,496,497,500],{},"The 2038 problem only affects ",[19,498,499],{},"32-bit signed"," integers",[10,502,504],{"id":503},"related-guides","Related Guides",[111,506,507,514,520],{},[114,508,509],{},[510,511,513],"a",{"href":512},"\u002Fguides\u002Ftimestamp-formats-explained","Timestamp Formats Explained",[114,515,516],{},[510,517,519],{"href":518},"\u002Fguides\u002Fdatetime-programming-tips","DateTime Programming Tips",[114,521,522],{},[510,523,525],{"href":524},"\u002Fguides\u002Fcron-syntax-guide","Cron Syntax Guide",[10,527,529],{"id":528},"try-it-yourself","Try It Yourself",[15,531,532,533,537],{},"Use our free ",[510,534,536],{"href":535},"\u002Ftools\u002Ftimestamp-converter","Timestamp Converter"," to convert Unix timestamps to human-readable dates and back — right in your browser.",[539,540,541],"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 .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}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":30,"searchDepth":138,"depth":138,"links":543},[544,545,546,547,548,552,553,554],{"id":12,"depth":138,"text":13},{"id":39,"depth":138,"text":40},{"id":217,"depth":138,"text":218},{"id":248,"depth":138,"text":249},{"id":292,"depth":138,"text":293,"children":549},[550,551],{"id":297,"depth":174,"text":298},{"id":322,"depth":174,"text":323},{"id":462,"depth":138,"text":463},{"id":503,"depth":138,"text":504},{"id":528,"depth":138,"text":529},"2026-05-27","Learn what Unix timestamps are, how epoch time works, and why developers use them for date and time handling.","md",{"immutable":380},"\u002Fguides\u002Funix-timestamp-guide",{"title":5,"description":556},"guides\u002Funix-timestamp-guide","FMQxpikle3no6kv0id2wrvdGvofMgaFGe4L4WAKdEhU",1780401325645]