www.colben.cn/content/post/python-time.md
2021-11-14 14:32:08 +08:00

47 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Python 的 time 模块"
date: 2019-10-30T17:49:27+08:00
lastmod: 2019-10-30T17:49:27+08:00
tags: ["python", "time"]
categories: ["python"]
---
- 时间戳: 相对1970.1.1 00:00:00计算的秒数
- struct_time: year(2015) month(1-12) day(1-31) hours(0-23) minutes(0-59) seconds(0-59) weekday(0-6,Monday is 0) julian day(day in the year,1-366) DST flag(-1,0,1)
- time.asctime([tuple]) #把struct_time 转成字符串
- time.clock() #第一次调用返回程序运行的实际时间,后面调用返回与第一次调用的时间间隔
- time.sleep() #推迟指定秒的时间
- time.ctime() #把时间戳(默认当前时间)转成字符串
- time.gmtime() #把时间戳(默认当前时间)转成UTC时区的struct_time
- time.localtime() #把时间戳(默认当前时间)转成当前时区的struct_time
- time.mktime() #把struct_time转成时间戳
- time.strftime(format[,tuple]) #把struct_time(默认当前时间)根据制定字符串输出
- strptime(string, format) #把时间字符串根据指定的格式转成struct_time
- time.time() #返回当前时间的时间戳
- python中时间日期格式化符号
- %y 两位数的年份表示00-99
- %Y 四位数的年份表示000-9999
- %m 月份01-12
- %d 月内中的一天0-31
- %H 24小时制小时数0-23
- %I 12小时制小时数01-12
- %M 分钟数00 = 59
- %S 秒00-59
- %a 本地简化星期名称
- %A 本地完整星期名称
- %b 本地简化的月份名称
- %B 本地完整的月份名称
- %c 本地相应的日期表示和时间表示
- %j 年内的一天001-366
- %p 本地A.M.或P.M.的等价符
- %U 一年中的星期数00-53星期天为星期的开始
- %w 星期0-6星期天为星期的开始
- %W 一年中的星期数00-53星期一为星期的开始
- %x 本地相应的日期表示
- %X 本地相应的时间表示
- %Z 当前时区的名称
- %% %号本身