日時
実行時の日時を取得する
import datetime
# 実行時の日時を表すdatetimeインスタンスを返す
now = datetime.datetime.now()
# 年-月-日 時:分:秒.マイクロ秒
print now #=> 2012-04-04 19:21:45.828625
# 年
print now.year #=> 2012
# 月
print now.month #=> 4
# 日
print now.day #=> 4
# 時
print now.hour #=> 19
# 分
print now.minute #=> 21
# 秒
print now.second #=> 45
# マイクロ秒
print now.microsecond #=> 828625
ある月の日数を取得する
import calendar
# 2012年4月に関するタプルを返す
(wday_1st, days) = calendar.monthrange(2012,4)
# 指定した年月の1日の曜日
print wday_1st #=> 6
# 指定した年月の日数
print days #=> 30
最終更新:2012年04月04日 19:34