前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python中time.time()和

python中time.time()和

作者头像
py3study
发布2020-01-12 23:33:23
1.2K0
发布2020-01-12 23:33:23
举报
文章被收录于专栏:python3python3

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • vi a1.py
  • python a1.py
  • vi a2.py
  • python a2.py
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档