Python中与时间处理相关的包

date

In [1]: from datetime import date

In [2]: date.today()
Out[2]: datetime.date(2018, 11, 1)

In [3]: date.today().isoformat()
Out[3]: '2018-11-01'

Time

In [4]: import time

In [5]: t = time.time()

In [6]: t
Out[6]: 1541079791.9093795

In [7]: print(type(time.time))


In [8]: t2 = lambda:date.today().isoformat()

In [9]: type(t2)
Out[9]: function

字符串和datetime之间的相互转换

In [44]: import datetime                                                                                                                                       
In [45]: t1 = datetime.datetime.now()                                                                                                                          
In [46]: format_demo = "%Y-%m-%d %H:%M:%S"                                                                                                                     
In [47]: t2 = t1.strftime(format_demo)                                                                                                                         
In [48]: t2                                                                                                                                                    
Out[48]: '2018-11-01 13:53:29'
In [49]: type(t2)                                                                                                                                              
Out[49]: str
In [50]: t3 = datetime.datetime.strptime(t2,format_demo)                                                                                                       
In [51]: t3                                                                                                                                                    
Out[51]: datetime.datetime(2018, 11, 1, 13, 53, 29)
In [52]: type(t3)                                                                                                                                              
Out[52]: datetime.datetime

你可能感兴趣的:(开发实践)