String 转 DateTime
1 | In [16]: time_str = '2018-02-28 14:00:00' |
DateTime 转 String
1 | In [19]: date_time = datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S") |
DateTime 转 时间戳
1 | In [21]: date_time |
时间戳转String
1 | In [22]: time.mktime(date_time.timetuple()) |
Date转DateTime
1 | In [25]: date = datetime.date.today() |
指定日期
1 | In [30]: datetime.datetime(2018,2,28) |
获取几天前
1 | In [43]: a = datetime.datetime.combine(datetime.date.today(),datetime.time.min) |
日期中不要前面的0
1 | # 例如:01、02、03只要1、2、3 |