1 import datetime as dt
2 import time as tm
%时间从纪元开始以秒为单位返回当前时间。(1970年1月1日)
1
tm.time()
1520242063.03

1 dtnow = dt.datetime.fromtimestamp(tm.time())
2 dtnow
datetime.datetime(2018, 3, 5, 9, 27, 54, 629264)

1 dtnow.year, dtnow.month, dtnow.day, dtnow.hour, dtnow.minute, dtnow.second # get year, month, day, etc.from a datetime
(2018, 3, 5, 9, 27, 54)

%timedelta是持续表达两个日期之间的差异。
1
delta = dt.timedelta(days = 100) # create a timedelta of 100 days 2 delta
datetime.timedelta(100)

%date.today()返回当前的时间
1
today = dt.date.today()
2 today - delta # the date 100 days ago
datetime.date(2017, 11, 25)

1 today > today-delta # compare dates
True








posted on 2018-03-05 19:56  郑哲  阅读(222)  评论(0编辑  收藏  举报