Don't understand german? Read or subscribe to my english-only feed.

Unix time: 1234567890

I hope you know the comics of xkcd and abstrusegoose about Unix time. Unix time?

Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds. It is widely used not only on Unix-like operating systems but also in many other computing systems.

http://en.wikipedia.org/wiki/Unix_time

This are my solutions to convert the Unix time ‘1234567890’ to human readable format:

GNU date:

% date -d @1234567890
Sat Feb 14 00:31:30 CET 2009

BSD date:

% date -ur 1234567890
Sat Feb 14 00:31:30 CET 2009

Zsh:

% zsh -c 'zmodload zsh/datetime ; strftime "%c" 1234567890'
Sat 14 Feb 2009 12:31:30 AM CET

Python:

% python -c 'import time; print time.ctime(1234567890)'
Sat Feb 14 00:31:30 2009

Ruby:

% ruby -e 'puts Time.at(1234567890)'
Sat Feb 14 00:31:30 +0100 2009

Perl:

% perl -e 'print scalar localtime(1234567890),"\n";'
Sat Feb 14 00:31:30 2009

MySQL:

% echo 'select FROM_UNIXTIME(1234567890);' | mysql -h localhost
FROM_UNIXTIME(1234567890)
2009-02-14 00:31:30

PostgreSQL:

% echo "SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 1234567890 * INTERVAL '1 second';" | psql test
        ?column?
------------------------
 2009-02-14 00:31:30+01
(1 row)

C:

% echo '
#include <stdio.h>
#include <time.h>

int main() {
   time_t sec;
   struct tm * ts;
   sec = (1234567890);
   ts = localtime(&sec);
   printf("%s", ctime(&sec));
   return 0;
}' | gcc -x c - && ./a.out
Sat Feb 14 00:31:30 2009

Java:

% cat date.java
import java.util.Date;
import java.util.TimeZone;

class UnixTime {
        public static void main(String[] args) {
                TimeZone.setDefault(TimeZone.getTimeZone("CET"));
                System.out.println(new Date(1234567890L*1000L));
        }
}
% javac date.java && java UnixTime
Sat Feb 14 00:31:30 CET 2009

Javascript:

% echo 'new Date(1234567890*1000);' | smjs -i
js> Sat Feb 14 2009 00:31:30 GMT+0100 (CET)

PHP:

% php --run 'print date("r", "1234567890");'
Sat, 14 Feb 2009 00:31:30 +0100

2 Responses to “Unix time: 1234567890”

  1. Der Adminblogger Says:

    At least the mysql version doesn’t need an echo:

    % mysql -h localhost -e ‘SELECT FROM_UNIXTIME(1234567890)’

  2. mika Says:

    @adminblogger: ah right, thanks :)

    regards,
    -mika-