python convert timestamp to date format

In simple terms, the timestamp is how many seconds the current time is from 1970-01-01T00:00:00Z.
For example, the current time is 10:32:50 on July 6, 2022, so the timestamp corresponding to this time point is 1657074770

1. Timestamp acquisition

import time
now=time.time()#获取当前时间时间戳

insert image description here

2. Convert millisecond-level timestamps to dates

When the timestamp is 1678723200000

import time
now = int(1678723200000/1000)
timeArray = time.localtime(now)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
print(otherStyleTime)

insert image description here

3. Second-level timestamp conversion

import time
now = time.time()
timeArray = time.localtime(now)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
print(now)
print(otherStyleTime)

insert image description here

Guess you like

Origin blog.csdn.net/qq_62975494/article/details/130118575