
Unix Timestamps Explained: Convert Between Dates and Epochs
Unix timestamps are the backbone of time handling in computing. Here is everything you need to know about converting between timestamps and dates. What is a Unix Timestamp? A Unix timestamp counts the number of seconds since January 1, 1970 00:00:00 UTC (the Unix epoch). Right now, it is around 1,772,000,000. JavaScript // Current timestamp (seconds) Math . floor ( Date . now () / 1000 ) // Timestamp to Date new Date ( 1672531200 * 1000 ) // 2023-01-01 // Date to Timestamp new Date ( ' 2023-01-01 ' ). getTime () / 1000 Python import time , datetime # Current timestamp int ( time . time ()) # Timestamp to datetime datetime . datetime . fromtimestamp ( 1672531200 ) # Datetime to timestamp int ( datetime . datetime ( 2023 , 1 , 1 ). timestamp ()) Milliseconds vs Seconds Source Format Example Unix/Python Seconds 1672531200 JavaScript Milliseconds 1672531200000 Java Milliseconds 1672531200000L Common Gotchas Timezone confusion - timestamps are always UTC Seconds vs milliseconds - JavaScript
Continue reading on Dev.to Webdev
Opens in a new tab




