Python/サンプル/日時情報の取得方法・datetime
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* 日時情報の取得方法・datetime [#b02c4564]
Pythonで日付や時間を取得するサンプルコードを以下に記しま...
#contents
#htmlinsertpcsp(ll-top.html,ll-sp.html)
* 関連記事 [#t21ac96e]
-[[PythonでUNIX時間を取得する方法>Python/サンプル/Python...
-[[Pythonで日時情報を取得する方法・datetime>Python/サンプ...
-[[Pythonで日時情報の整形(フォーマット)・strftime>Python/...
* 動作確認環境 [#cb944995]
$ python --version
Python 2.7.3
$ lsb_release -d
Description: Ubuntu 12.04.4 LTS
* 日時の取得サンプルコード [#r67b44d1]
datetimeモジュールを使用し日付、時間を取得します。
** 日時の取得サンプルコード [#j1a21988]
- サンプルコード
import datetime
print datetime.date.today()
print datetime.datetime.today()
上記のサンプルコードでは、日付のみと日付と時間を取得する...
-実行結果~
日付のみと日付+時刻の出力がされているのが確認できます。
2014-02-26
2014-02-26 11:01:08.521838
** 各要素ごとに取得するサンプルコード [#p0c466ea]
-サンプルコード~
datetime.datetime.today()により取得した各種情報を1つずつ...
import datetime
d = datetime.datetime.today()
print "year: ", d.year
print "month: ", d.month
print "day: ", d.day
print "hour: ", d.hour
print "minute: ", d.minute
print "second: ", d.second
print "microsecond:", d.microsecond
-実行結果
year: 2014
month: 2
day: 26
hour: 11
minute: 30
second: 38
microsecond: 291912
以上、datetimeモジュールによる日付および時間の取得方法で...
#htmlinsertpcsp(ll-btm.html,ll-sp.html)
終了行:
#navi(../)
* 日時情報の取得方法・datetime [#b02c4564]
Pythonで日付や時間を取得するサンプルコードを以下に記しま...
#contents
#htmlinsertpcsp(ll-top.html,ll-sp.html)
* 関連記事 [#t21ac96e]
-[[PythonでUNIX時間を取得する方法>Python/サンプル/Python...
-[[Pythonで日時情報を取得する方法・datetime>Python/サンプ...
-[[Pythonで日時情報の整形(フォーマット)・strftime>Python/...
* 動作確認環境 [#cb944995]
$ python --version
Python 2.7.3
$ lsb_release -d
Description: Ubuntu 12.04.4 LTS
* 日時の取得サンプルコード [#r67b44d1]
datetimeモジュールを使用し日付、時間を取得します。
** 日時の取得サンプルコード [#j1a21988]
- サンプルコード
import datetime
print datetime.date.today()
print datetime.datetime.today()
上記のサンプルコードでは、日付のみと日付と時間を取得する...
-実行結果~
日付のみと日付+時刻の出力がされているのが確認できます。
2014-02-26
2014-02-26 11:01:08.521838
** 各要素ごとに取得するサンプルコード [#p0c466ea]
-サンプルコード~
datetime.datetime.today()により取得した各種情報を1つずつ...
import datetime
d = datetime.datetime.today()
print "year: ", d.year
print "month: ", d.month
print "day: ", d.day
print "hour: ", d.hour
print "minute: ", d.minute
print "second: ", d.second
print "microsecond:", d.microsecond
-実行結果
year: 2014
month: 2
day: 26
hour: 11
minute: 30
second: 38
microsecond: 291912
以上、datetimeモジュールによる日付および時間の取得方法で...
#htmlinsertpcsp(ll-btm.html,ll-sp.html)
ページ名: