标签(空格分隔): Python-标准库
- [x] 对日期、时间、时间戳的处理
- [x] datetime 类
- [x] 类方法
today()返回本地时区当前时间的datetime对象now(tz=None)返回当前时间的datetime对象,时间到微秒 如果tz等于None返回和today()一样utcnow()没有时区的当前时间fromtimestamp(timestamp, tz=None)从一个时间戳返回一个datetime对象
- [x]
datetime对象timestamp()返回一个到微妙的时间戳- 时间戳: 格林威治时间 1970年到1月1日0点 到现在的秒数
- 构造方法,
datetime.datetime(2016, 12, 6, 16, 29, 43, 79043) - year、month、day、hour、minute、secound、microsecond, 取 datetime 对象的年月日时分秒及微妙
weekday()返回星期的天, 周一 0, 周日 6isoweekday()返回星期的天,周一 1, 周日 7date()返回日期 date 对象time()返回时间 time 对象replace()修改并返回新的时间isocalendar()返回 一个三元组 (年,周数,周的天) --- 日历的使用
- [x] 类方法
- [x] 日期格式化
- 类方法
strptime(date_string, format), 返回datetime对象 - 对象方法
strftime(format), 返回字符串 - 字符串
format函数格式化
- 类方法
标签(空格分隔): Python-标准库
- [x] 对日期、时间、时间戳的处理
- [x] datetime 类
- [x] 类方法
today()返回本地时区当前时间的datetime对象now(tz=None)返回当前时间的datetime对象,时间到微秒 如果tz等于None返回和today()一样utcnow()没有时区的当前时间fromtimestamp(timestamp, tz=None)从一个时间戳返回一个datetime对象
- [x]
datetime对象timestamp()返回一个到微妙的时间戳- 时间戳: 格林威治时间 1970年到1月1日0点 到现在的秒数
- 构造方法,
datetime.datetime(2016, 12, 6, 16, 29, 43, 79043) - year、month、day、hour、minute、secound、microsecond, 取 datetime 对象的年月日时分秒及微妙
weekday()返回星期的天, 周一 0, 周日 6isoweekday()返回星期的天,周一 1, 周日 7date()返回日期 date 对象time()返回时间 time 对象replace()修改并返回新的时间isocalendar()返回 一个三元组 (年,周数,周的天) --- 日历的使用
- [x] 类方法
- [x] 日期格式化
- 类方法
strptime(date_string, format), 返回datetime对象 - 对象方法
strftime(format), 返回字符串 - 字符串
format函数格式化
- 类方法
import datetime dt = datetime.datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M") print(dt.strftime("%Y-%m-%d %H:%M:%S")) print("{0:%Y}-{0:%m}-{0:%d} {0:%H}:{0:%M}:{0:%S}".format(dt))
- [x]
timedelta对象- 构造方法
datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)---> 返回一个 timedelta 使用时间对象,可以和datetime对象相加减total_seconds()返回时间差的总秒数
from datetime import datetime, timedelta nowtime = datetime(year=2019, month=10, day=1, hour=12, minute=15) print(nowtime) # 2019-10-01 12:15:00 new_time = nowtime + timedelta(days=3, hours=0.5) print(new_time) # 2019-10-04 12:45:00 # 时间差,3天零30分钟 delta = (new_time - nowtime).total_seconds() print(delta) # 261000.0 差值秒数
- [x]
timedelta对象- 构造方法
datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)---> 返回一个 timedelta 使用时间对象,可以和datetime对象相加减total_seconds()返回时间差的总秒数
from datetime import datetime, timedelta nowtime = datetime(year=2019, month=10, day=1, hour=12, minute=15) print(nowtime) # 2019-10-01 12:15:00 new_time = nowtime + timedelta(days=3, hours=0.5) print(new_time) # 2019-10-04 12:45:00 # 时间差,3天零30分钟 delta = (new_time - nowtime).total_seconds() print(delta) # 261000.0 差值秒数
来源:博客园
作者:佛系小生
链接:https://www.cnblogs.com/jingru-QAQ/p/11413100.html