Unix Epoch Programming Reference
Below is a table indicating how to obtain a Unix Epoch Timestamp from various programming languages:
Language | Command |
---|---|
Actionscript |
(new Date()).time |
ASP |
DateDiff("s", "01/01/1970 00:00:00", Now()) |
C++ |
#include <ctime> std::time(0); |
C# |
epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000; |
Erlang |
calendar:datetime_to_gregorian_seconds( calendar:now_to_universal_time( now()) )-719528*24*3600 |
Java |
long epoch = System.currentTimeMillis()/1000; |
JavaScript |
Math.round(new Date().getTime()/1000.0)Â getTime() |
MSSQL |
SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE()) |
MySQL |
SELECT unix_timestamp(now()) |
*Nix Shell |
date +%s |
Oracle |
SELECT (SYSDATE - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) * 24 * 60 * 60 FROM DUAL |
Perl |
time |
PHP |
time() |
PostgreSQL |
SELECT extract(epoch FROM now()); |
PowerShell |
Get-Date -UFormat "%s" |
Python |
import time time.time() |
Ruby |
Time.now.to_i |
VBScript |
DateDiff("s", "01/01/1970 00:00:00", Now()) |