Python/サンプル/PythonでUNIX時間を取得する方法
の編集
Top
/
Python
/
サンプル
/
PythonでUNIX時間を取得する方法
[
トップ
] [
編集
|
差分
|
バックアップ
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
(no template pages)
#navi(../) * PythonでUNIX時間を取得する方法 [#mba60110] PythonでUNIX時間を取得するサンプルコードを以下に記します。 #contents #htmlinsertpcsp(ll-top.html,ll-sp.html) * 参考記事 [#b828e48f] -[[PythonでUNIX時間を取得する方法>Python/サンプル/PythonでUNIX時間を取得する方法]] -[[Pythonで日時情報を取得する方法・datetime>Python/サンプル/日時情報の取得方法・datetime]] -[[Pythonで日時情報の整形(フォーマット)・strftime>Python/サンプル/日時情報のフォーマット・strftime]] [[linux.just4fun.bizの記事>http://linux.just4fun.biz/]] -[[逆引きUNIXコマンド UNIX時間に変換・UNIX時間を取得する方法>http://linux.just4fun.biz/%E9%80%86%E5%BC%95%E3%81%8DUNIX%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89/UNIX%E6%99%82%E9%96%93%E3%81%AB%E5%A4%89%E6%8F%9B%E3%83%BBUNIX%E6%99%82%E9%96%93%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95.html]] * 動作確認環境 [#c88f9854] -OS $ lsb_release -d Description: Ubuntu 12.04.4 LTS -Python $ python --version Python 2.7.3 * UNIX時間を取得するサンプルコード [#y246cfdf] #ref(unixtime.py) #!/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タイムが取得できていることが確認できました。 #htmlinsertpcsp(ll-btm.html,ll-sp.html)
タイムスタンプを変更しない
#navi(../) * PythonでUNIX時間を取得する方法 [#mba60110] PythonでUNIX時間を取得するサンプルコードを以下に記します。 #contents #htmlinsertpcsp(ll-top.html,ll-sp.html) * 参考記事 [#b828e48f] -[[PythonでUNIX時間を取得する方法>Python/サンプル/PythonでUNIX時間を取得する方法]] -[[Pythonで日時情報を取得する方法・datetime>Python/サンプル/日時情報の取得方法・datetime]] -[[Pythonで日時情報の整形(フォーマット)・strftime>Python/サンプル/日時情報のフォーマット・strftime]] [[linux.just4fun.bizの記事>http://linux.just4fun.biz/]] -[[逆引きUNIXコマンド UNIX時間に変換・UNIX時間を取得する方法>http://linux.just4fun.biz/%E9%80%86%E5%BC%95%E3%81%8DUNIX%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89/UNIX%E6%99%82%E9%96%93%E3%81%AB%E5%A4%89%E6%8F%9B%E3%83%BBUNIX%E6%99%82%E9%96%93%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95.html]] * 動作確認環境 [#c88f9854] -OS $ lsb_release -d Description: Ubuntu 12.04.4 LTS -Python $ python --version Python 2.7.3 * UNIX時間を取得するサンプルコード [#y246cfdf] #ref(unixtime.py) #!/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タイムが取得できていることが確認できました。 #htmlinsertpcsp(ll-btm.html,ll-sp.html)
テキスト整形のルールを表示する
添付ファイル:
unixtime.py
604件
[
詳細
]