import time, datetime # 1662541290 print(int(time.time())) t = datetime.datetime.now() # 2022-09-07 17:01:30.954448 print(t) # 2022-09-07 17:03:09 print(t.strftime('%Y-%m-%d %H:%M:%S')) # 一个小时后 2022-09-07 18:04:57 t += datetime.timedelta(hours=1) print(t.strftime('%Y-%m-%d %H:%M:%S')) # 时间戳转固定格式时间 ts = int(time.time()) time_arr = time.localtime(ts) time_str = time.strftime('%Y--%m--%d %H--%M--%S') print(time_str) # 时间转时间搓 t2 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') time_arr2 = time.strptime(t2, '%Y-%m-%d %H:%M:%S') times = time.mktime(time_arr2) print(times)
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/288146.html