python date time

   现在时刻

from datetime import datetime
now=datetime.now()

   本地时间

now
Out[45]: datetime.datetime(2017, 4, 12, 14, 4, 39, 846687)

   世界时间

datetime.utcnow()
Out[46]: datetime.datetime(2017, 4, 12, 6, 7, 47, 338687)
now.year
Out[55]: 2017

now.month
Out[56]: 4

now.day
Out[57]: 12

type(now)
Out[58]: datetime.datetime

   计算时间差

delta=datetime(2011,1,7)-datetime(2008,6,24,8,15)

delta
Out[60]: datetime.timedelta(926, 56700)

delta.days
Out[61]: 926

delta.seconds
Out[62]: 56700
posted @ 2022-08-19 23:00  luoganttcc  阅读(18)  评论(0编辑  收藏  举报