Saturday, November 28, 2009

Unix Epoch Time

date +%s

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'. Many Unix 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).

Perltime
PHPtime()
RubyTime.now (or Time.new). To display the epoch: Time.now.to_i
Pythonimport time first, then time.time()
Javalong epoch = System.currentTimeMillis()/1000;
Microsoft .NET C#epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
VBScript/ASPDateDiff("s", "01/01/1970 00:00:00", Now())
Erlangcalendar:datetime_to_gregorian_seconds(calendar:now_to_universal_time( now()))-719528*24*3600.
MySQLSELECT unix_timestamp(now()) More information
PostgreSQLSELECT extract(epoch FROM now());
SQL ServerSELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
JavaScriptMath.round(new Date().getTime()/1000.0) getTime() returns time in milliseconds.
Unix/Linuxdate +%s
Other OS's Command line: perl -e "print time" (If Perl is installed on your system)

No comments: