-
Notifications
You must be signed in to change notification settings - Fork 0
/
44_datetime.py
45 lines (31 loc) · 872 Bytes
/
44_datetime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# coding=utf-8
from __future__ import print_function
from datetime import datetime, timedelta
now = datetime.now()
print(now)
print('\n')
str_date = datetime.strftime(now, '%Y-%m-%d %H:%M:%S')
print('%s, type = %s' % (str_date, type(str_date)))
date1 = datetime.strptime(str_date, '%Y-%m-%d %H:%M:%S')
print('%s, type = %s' % (date1, type(date1)))
print('\n')
date2 = date1.replace(year=2016, month=12, day=10, hour=10, minute=25, second=3)
print(date2)
print('\n')
# d = datetime.date(2015, 4, 15)
# t = datetime.time(12, 23, 38)
# dt = datetime.combine(d, t)
# print dt
print('\n')
nowTuple = now.timetuple()
print(nowTuple)
print(type(nowTuple.tm_year))
print(nowTuple.tm_mon)
print(nowTuple.tm_mday)
print(nowTuple.tm_hour)
print(nowTuple.tm_min)
print(nowTuple.tm_sec)
print('\n')
nowDelta = now + timedelta(days=1, weeks=5)
print(nowDelta)
print('\n')