seconds or milliseconds? count the digits on your unix timestamp
quick one because this bites me every few weeks. you get a number like 1791216000 in a log or an API response and you need to know what date it is. the trick is just count the digits. 10 digits is seconds, 13 is millise
quick one because this bites me every few weeks. you get a number like 1791216000 in a log or an API response and you need to know what date it is.
the trick is just count the digits. 10 digits is seconds, 13 is milliseconds, 16 is microseconds, 19 is nanoseconds. that works for any date between 2001 and 2286.
1791216000 seconds (php time(), jwt exp, most databases)
1791216000000 milliseconds (JS Date.now(), java currentTimeMillis)
that one is 5 Oct 2026, 16:00 UTC, so 9:30 pm in India since IST is UTC+5:30. same instant everywhere, only the reader's zone changes.
if the converted date looks absurd the unit is wrong, not the timestamp. read milliseconds as seconds and you land about 56,000 years in the future. read seconds as milliseconds and you land on 21 January 1970, which is always the giveaway.
by hand you can also divide by 86400, that gives whole days since 1970 and the leftover seconds are the time of day. nobody does this in practice but it helps to see it once.
and yes there is the 2038 thing, signed 32 bit seconds run out on 19 January 2038. if you store timestamps in a 32 bit int, move to 64 bit now.
i made a converter for this that detects the unit itself and shows IST by default, honestly i use it more than anything else i built: https://theomnikit.com/guides/read-a-unix-timestamp?utm_source=devto&utm_medium=post&utm_campaign=read-a-unix-timestamp
(drafted with some AI help, edited by me)
originally posted on theomnikit: https://theomnikit.com/guides/read-a-unix-timestamp?utm_source=devto&utm_medium=post&utm_campaign=read-a-unix-timestamp
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.