Time stamp date and Date to time stamp
ticks = time.time() # Get the timestamp
print("ticks:",ticks)
localdate = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ticks))# Time stamp date
print("localdate:",localdate)
date_to_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(a))# Date to time stamp
print("date_to_time:",date_to_time)
----------------------------------
ticks: 1653623433.5224512
localdate: 2022-05-27 11:50:33
date_to_time: 2022-05-25 11:50:33
Time stamping ISO Time
ticks = time.time() # Get the timestamp
localdate = datetime.fromtimestamp(ticks) # Turn the timestamp to datetime.datetime type 2022-05-27 13:40:57.899528
# Or directly datetime.now() obtain datetime.datetime Type date
#astimezone Change the time zone ,isoformat() With iso Format output time string
iso_date = localdate.astimezone().isoformat()
print("ISO Time ",iso_date)
Remove iso Extra characters after
location = iso_date.rfind('.')
date = iso_date[:location]
print(" After removing :",date)
---------------------
ISO Time 2022-05-27T13:50:34.410212+08:00 <class 'str'>
After removing :2022-05-27T13:50:34
List of articles 1. Non operat
One .Python Environmental inst