步骤:
1. 掌握几种对象及其关系
2. 了解每类对象的基本操作方法
3. 通过转化关系转化
涉及对象
1. datetime
> import datetime > now = datetime.datetime.now() > now datetime.datetime(2018, 1, 12, 23, 9, 12, 946118) > type(now) <type 'datetime.datetime'>
2. timestamp
> import time > time.time() 1421075455.568243
3. time tuple
> import time > time.localtime() time.struct_time(tm_year=2015, tm_mon=1, tm_mday=12, tm_hour=23, tm_min=10, tm_sec=30, tm_wday=0, tm_yday=12, tm_isdst=0)
4. string
> import datetime > datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") '2015-01-12 23:13:08'
5. date
> import datetime > datetime.datetime.now().date() datetime.date(2015, 1, 12)
datetime基本操作
1. 获取当前datetime
> import datetime > datetime.datetime.now() datetime.datetime(2015, 1, 12, 23, 26, 24, 475680)
2. 获取当天date
> datetime.date.today() datetime.date(2015, 1, 12)
3. 获取明天/前N天
明天
> datetime.date.today() + datetime.timedelta(days=1) datetime.date(2015, 1, 13)
三天前
> datetime.datetime.now() datetime.datetime(2015, 1, 12, 23, 38, 55, 492226) > datetime.datetime.now() - datetime.timedelta(days=3) datetime.datetime(2015, 1, 9, 23, 38, 57, 59363)
4. 获取当天开始和结束时间(00:00:00 23:59:59)
> datetime.datetime.combine(datetime.date.today(), datetime.time.min) datetime.datetime(2015, 1, 12, 0, 0) > datetime.datetime.combine(datetime.date.today(), datetime.time.max) datetime.datetime(2015, 1, 12, 23, 59, 59, 999999)
5. 获取两个datetime的时间差
> (datetime.datetime(2015,1,13,12,0,0) - datetime.datetime.now()).total_seconds() 44747.768075
6. 获取本周/本月/上月最后一天
本周
> today = datetime.date.today() > today datetime.date(2015, 1, 12) > sunday = today + datetime.timedelta(6 - today.weekday()) > sunday datetime.date(2015, 1, 18)
本月
> import calendar > today = datetime.date.today() > _, last_day_num = calendar.monthrange(today.year, today.month) > last_day = datetime.date(today.year, today.month, last_day_num) > last_day datetime.date(2015, 1, 31)
获取上个月的最后一天(可能跨年)
> import datetime > today = datetime.date.today() > first = datetime.date(day=1, month=today.month, year=today.year) > lastMonth = first - datetime.timedelta(days=1)
关系转换
几个关系之间的转化
Datetime Object / String / timestamp / time tuple
关系转换例子
datetime <=> string
datetime -> string
> import datetime > datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") '2015-01-12 23:13:08'
string -> datetime
> import datetime > datetime.datetime.strptime("2014-12-31 18:20:10", "%Y-%m-%d %H:%M:%S") datetime.datetime(2014, 12, 31, 18, 20, 10)
datetime <=> timetuple
datetime -> timetuple
> import datetime > datetime.datetime.now().timetuple() time.struct_time(tm_year=2015, tm_mon=1, tm_mday=12, tm_hour=23, tm_min=17, tm_sec=59, tm_wday=0, tm_yday=12, tm_isdst=-1)
timetuple -> datetime
timetuple => timestamp => datetime [看后面datetime<=>timestamp]
datetime <=> date
datetime -> date
> import datetime > datetime.datetime.now().date() datetime.date(2015, 1, 12)
date -> datetime
> datetime.date.today() datetime.date(2015, 1, 12) > today = datetime.date.today() > datetime.datetime.combine(today, datetime.time()) datetime.datetime(2015, 1, 12, 0, 0) > datetime.datetime.combine(today, datetime.time.min) datetime.datetime(2015, 1, 12, 0, 0)
datetime <=> timestamp
datetime -> timestamp
> now = datetime.datetime.now() > timestamp = time.mktime(now.timetuple()) > timestamp 1421077403.0
timestamp -> datetime
> datetime.datetime.fromtimestamp(1421077403.0) datetime.datetime(2015, 1, 12, 23, 43, 23)
这篇文章就介绍到这了,基本上都是python的关于日期时间操作的基础知识点,需要掌握好
PYTHON时间日期
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]