标签:python开发 包装 .com new images 否则 存在 使用 time
1 from datetime import datetime 2 now_time = datetime.now() 3 a = now_time.strftime(‘%Y-%m-%d‘) 4 print(now_time) 5 print(a) 6 print(type(now_time))
1 from datetime import datetime,timedelta 2 now_time = datetime.now() 3 a = now_time.strftime(‘%c‘) 4 print(now_time) 5 print(a) 6 b = now_time + timedelta(days =-1) 7 print(b)
1 import time 2 3 for i in xrange(1,4): 4 print (i) 5 time.sleep(0.1) 6 7 #datetime 8 9 from datetime import datetime, timedelta 10 11 now_time = datetime.now() 12 print(now_time) 13 new_time = now_time.strftime(‘%Y-%m-%d %H:%M:%S‘) 14 a = now_time.strftime(‘%c‘) 15 print(new_time) 16 print(a)
1 print(‘#‘*30) 2 now_time = datetime.now() 3 yesterday = now_time + timedelta(days =- 1) 4 tomorrow = now_time + timedelta(days =- 1) 5 tomorrow_1 = now_time + timedelta(days=-1) 6 tomorrow = tomorrow_1.strftime(‘%Y-%m-%d‘) 7 print(yesterday) 8 print(tomorrow)
1 from datetime import datetime,timedelta 2 string = ‘2017-04-25 11:59:58‘ 3 time1 = datetime.strptime(string,‘%Y-%m-%d %H:%M:%S‘) 4 print(time1) 5 print(type(time1))
1 from datetime import datetime,timedelta 2 string = ‘2017-04-25 11:59:58‘ 3 time1 = datetime.strptime(string,‘%Y-%m-%d %H:%M:%S‘) 4 print(time1) 5 print(type(time1)) 6 time1_str = datetime.strftime(time1,‘%Y-%m-%d %H:%M:%S‘) 7 print(type(time1_str)) 8 print(time1_str)
1 from datetime import datetime,timedelta 2 import time 3 time1 = time.time() 4 print(time1) 5 time1_str = datetime.fromtimestamp(time1) 6 print(time1_str) 7 print(type(time1_str))
1 from datetime import datetime 2 import time 3 4 now_time = datetime.now() 5 print(now_time) 6 print(type(now_time)) 7 print(‘###################time to str###################‘) 8 _time = now_time.strftime(‘%Y-%m-%d %H:%M:%S‘) 9 _time = datetime.strftime(now_time,‘%Y-%m-%d %H:%M:%S‘) 10 print(_time) 11 print(type(_time)) 12 print(‘###################str to time###################‘) 13 _d_time = datetime.strptime(_time,‘%Y-%m-%d %H:%M:%S‘) 14 print(_d_time) 15 print(type(_d_time)) 16 17 18 19 print(‘###################时间戳stamp###################‘) 20 #时间戳转换成时间对象 21 _a = time.time() 22 print(_a) 23 _n_time = datetime.fromtimestamp(_a) 24 print(_n_time) 25 print(type(_n_time))
day16——import、datetime获得时间、时间格式的相互转换
标签:python开发 包装 .com new images 否则 存在 使用 time
原文地址:http://www.cnblogs.com/yangjinbiao/p/7811614.html