Skip to content

时间函数

获取当前时间戳(天)

python
import time
def get_today():
    now = int(time.time())
    timeArray = time.localtime(now)
    today = time.strftime("%Y-%m-%d", timeArray)
    # print (today)
    return today

2022-12-03

获取当前时间戳(秒)

python
import time
def get_ts():
    now = int(time.time())
    timeArray = time.localtime(now)
    ts = time.strftime("%Y%m%d%H%M%S", timeArray)
    print (ts)
    return ts

20221203225816

python
import time
def get_ts():
    now = int(time.time())
    timeArray = time.localtime(now)
    ts = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
    print (ts)
    return ts

2022-12-03 22:58:16