PythonでUNIX時間を取得するサンプルコードを以下に記します。
$ lsb_release -d Description: Ubuntu 12.04.4 LTS
$ python --version Python 2.7.3
#!/usr/bin/python import time print time.time() print int(time.time())
上記のサンプルコードでUNIX時間を取得することができます。
intでキャストしている理由は time.time()の場合、小数点以下の値も返却されるためです。
上記のサンプルコードを実行した結果です。
dateコマンドのUNIX時間を出力するコマンドと同時に実行してみます。
$ chmod +x unixtime.py $ ./unixtime.py ; date +'%s' 1392882107.36 1392882107 1392882107
PythonのサンプルコードでUNIXタイムが取得できていることが確認できました。