python中time.time()和

2020-01-12 23:33:23 浏览数 (1)

python中time.time()和 time.strftime():

time.time()返回的是一个浮点数,以秒为单位,time.strftime后可以自定义格式,如time.strftime('%Y-%m-%d %H:%M:%S')

vi a1.py

#!/usr/bin/python

import time

t1 = time.time() print t1

t2 = time.strftime('%Y-%m-%d %H:%M:%S') print t2 :wq

python a1.py

今天、昨天、上月、去年:

vi a2.py

#!/usr/bin/python

import time today = time.strftime('%Y-%m-%d') yesterday = time.localtime()[2]-1 last_month = time.localtime()[1]-1 last_year = time.localtime()[0]-1 print today print yesterday print last_month print last_year :wq

python a2.py

0 人点赞