发布于2019-08-05 18:23 阅读(779) 评论(0) 点赞(1) 收藏(5)
····时间戳
print(time.time())
运行结果:
1 1564294158.0389376 2 3 Process finished with exit code 0
·····结构化时间
print(time.localtime()) # 当地时间 y = time.localtime() print(y.tm_year) print(y.tm_wday)
print(time.gmtime()) # 世界标准化时间 UTC
运行结果:
time.struct_time(tm_year=2019, tm_mon=7, tm_mday=28, tm_hour=14, tm_min=25, tm_sec=57, tm_wday=6, tm_yday=209, tm_isdst=0) 2019 6 time.struct_time(tm_year=2019, tm_mon=7, tm_mday=28, tm_hour=6, tm_min=25, tm_sec=57, tm_wday=6, tm_yday=209, tm_isdst=0) Process finished with exit code 0
·····结构化时间转换成时间戳
print(time.mktime(time.localtime()))
``````结构化时间转换成字符串时间
print(time.strftime('%Y-%m-%d %X',time.localtime()))
运行结果:
2019-07-28 14:34:58
Process finished with exit code 0
``````字符串时间转换成结构化时间
print(time.strptime('2018:1:1:12:00:00','%Y:%m:%d:%X'))
运行结果:
time.struct_time(tm_year=2018, tm_mon=1, tm_mday=1, tm_hour=12, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1)
Process finished with exit code 0
······把结构化时间转换成固定的字符串表达形式
print(time.asctime()) print(time.ctime())
运行结果:
Sun Jul 28 14:43:45 2019 Sun Jul 28 14:43:45 2019 Process finished with exit code 0
····推迟运行
print(time.sleep(1))
ps:
import datetime模块
print(datetime.datetime.now())
作者:python是我的菜
链接:https://www.pythonheidong.com/blog/article/6224/bff0257a45aa43a06cbc/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!