Created
May 2, 2013 00:24
-
-
Save letitride/5499379 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding: utf-8 | |
import datetime | |
if __name__ == "__main__": | |
#今日の日時 | |
day = datetime.date.today() | |
time = datetime.datetime.today() | |
print day | |
print time | |
#現在日の各要素 | |
print day.year | |
print day.month | |
print day.day | |
#現在時間の各要素 | |
print time.year | |
print time.month | |
print time.day | |
print time.hour | |
print time.minute | |
print time.second | |
print time.microsecond | |
#ISO 8601 形式、 ‘YYYY-MM-DD’ 形式 | |
print day.isoformat() | |
#日時表現文字列の生成 | |
# http://docs.python.jp/2/library/datetime.html#strftime-strptime-behavior | |
print time.strftime( "%Y/%m/%d %H:%M:%S" ) | |
#明日の日付 | |
print day + datetime.timedelta(days=1) | |
#3日前 | |
print day + datetime.timedelta(days=-3) | |
print day - datetime.timedelta(days=3) | |
#2000年から今日までの日数 | |
diff = day - datetime.date(2000,1,1) | |
print diff.days |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment