Epoch & Unix Timestamp Conversion Tools
Epoch dates for the start and end of the year/month/day
Convert seconds to years, months, days, hours and minutes
What is epoch time?
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking, the epoch is Unix time 0 (midnight 1/1/1970), but 'epoch' is often used as a synonym for Unix time. Some systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038). The converter on this page converts timestamps in seconds (10-digit), milliseconds (13-digit) and microseconds (16-digit) to readable dates.
| Human-readable time | Seconds |
|---|---|
| 1 hour | 3600 seconds |
| 1 day | 86400 seconds |
| 1 week | 604800 seconds |
| 1 month (30.44 days) | 2629743 seconds |
| 1 year (365.25 days) | 31556926 seconds |
Code examples
How to get the current epoch time in code...
The first line for each language shows how to get the current epoch time. The second line shows how to convert an epoch timestamp to a human-readable date. Replace the example epoch time 1800000000 with your own value. All examples return the epoch timestamp in seconds (and not milliseconds).
The full list in the programming section also includes examples for converting human-readable dates to epoch time.
| Python | import time; time.time()import time; time.ctime(1800000000) |
| PHP | time()date('r', 1800000000); More PHP |
| JavaScript | Math.floor(new Date().getTime()/1000.0)new Date(1800000000*1000).toLocaleString() or toUTCString(). More JavaScript |
| Java | long epoch = System.currentTimeMillis()/1000;String date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (1800000000*1000)); |
| C | Use the C Epoch Converter routines |
| C++ | double now = std::chrono::duration_cast<std::chrono::seconds> (std::chrono::system_clock::now().time_since_epoch()).count(); |
| C# | DateTimeOffset.Now.ToUnixTimeSeconds()new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(epoch).ToShortDateString(); |
| Perl | timescalar localtime(1800000000); More Perl |
| Ruby | Time.now.to_iTime.at(1800000000) |
| Go | time.Now().Unix()time.Unix(1800000000, 0) More Go |
| R | as.numeric(Sys.time())as.POSIXct(1800000000, origin="1970-01-01", tz="GMT") |
| Lua | epoch = os.time([date])datestring = os.date([format[,epoch]]) |
| Dart | DateTime.now().millisecondsSinceEpoch ~/ 1000DateTime.fromMillisecondsSinceEpoch(1800000000*1000) |
| Delphi | Epoch := DateTimeToUnix(Now, False);myString := DateTimeToStr(UnixToDateTime(Epoch)); |
| PostgreSQL | SELECT EXTRACT(EPOCH FROM now());SELECT TO_TIMESTAMP(1800000000); |
| MySQL | SELECT UNIX_TIMESTAMP(NOW());SELECT FROM_UNIXTIME(1800000000); More MySQL |
| SQL Server | SELECT DATEDIFF(SECOND, '1970-01-01', GETUTCDATE());SELECT DATEADD(SECOND, 1800000000, '1970-01-01'); |
| SQLite | SELECT unixepoch();SELECT datetime(1800000000, 'unixepoch');
or local time zone: SELECT datetime(1800000000, 'unixepoch', 'localtime'); |
| Unix/Linux Shell | date +%sdate -d @1800000000 Replace '-d' with '-ud' for UTC time. |
| macOS | date +%sdate -j -r 1800000000 |
| PowerShell | [DateTimeOffset]::Now.ToUnixTimeSeconds()[DateTimeOffset]::FromUnixTimeSeconds(1800000000).LocalDateTime |
| Excel/LibreOffice Calc | =(A1 / 86400) + 25569 Format the result cell for date/time. The result is in GMT (A1 contains the epoch). For other time zones: =((A1 +/- time zone adjustment) / 86400) + 25569. |
| Find more examples on the programming page. | |
Thanks to everyone who sent me corrections and updates!
More date-related programming examples: What's the current week number? - What's the current day number?
Please note: All tools on this page are based on the date & time settings of your computer and use JavaScript to convert times. Some browsers use the current DST (Daylight Saving Time) rules for all dates in history. JavaScript does not support leap seconds.