from datetime Import datetime # current system time D = DateTime.Now () Print (D) # 2019-11-22 21 is: 20 is: 09.586674
2019-11-22 21:27:17.842169
from datetime Import datetime # Coordinated Universal Time Greenwich time, and we have a difference of eight hours, utc Coordinated Universal # Coordinated coordination # Universal universal d1 = DateTime.UtcNow () Print (d1)
2019-11-22 13:27:33.084041
from datetime Import datetime # Create a specified time datetime D2 = datetime (2018, 2,. 8, 12 is,. 8,. 8, 8886 ) Print (D2)
2018-02-08 12:08:08.008886
from datetime import datetime # 时间格式化 d = datetime.now() print(d) # 2019-11-22 21:47:24.393180 print(type(d)) # <class 'datetime.datetime'> s = d.strftime("%Y-%m-%d %H:%M:%S") print(s) # 2019-11-22 21:47:24 d = datetime.now().strftime("%Y-%m-%d %H:%M:%S") print(d) # 2019-11-22 21:47:24
2019-11-22 21:47:24.393180 <class 'datetime.datetime'> 2019-11-22 21:47:24 2019-11-22 21:47:24
from datetime Import datetime # string converted into time str_date = INPUT ( " Please enter a time (dd-mm-format HH YYYY: the MM: the SS): " ) D = datetime.strptime (str_date, " % Y-M-% D% H%:% M:% S " ) Print (D) Print (type (D))
Enter a time (dd-mm-format HH YYYY: the MM: the SS): 2019-11-22 12:22:22 2019-11-22 12:22:22 <class 'A datetime.datetime'>
from datetime Import datetime # calculates the time difference D1 = datetime (2019,. 11, 22 is, 12 is, 22 is, 22 is ) D2 = datetime (2019,. 11, 21 is, 12 is, 22 is, 22 is ) the diff = D1 - D2 Print (diff.seconds) # simply be calculated from the minutes and seconds Print (diff.total_seconds ()) # including date calculation
0 86400.0