av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

Python datetime模塊的使用示例

瀏覽:53日期:2022-06-28 14:42:24
1、獲取當前年月日時分秒

# -*- encoding=utf-8 -*-import datetimenow = datetime.datetime.now()print('now:{}'.format(now))year = now.yearprint('year:{}'.format(year))month = now.monthprint('month:{}'.format(month))day = now.dayprint('day:{}'.format(day))hour = now.hourprint('hour:{}'.format(hour))minute = now.minuteprint('minute:{}'.format(minute))second = now.secondprint('second:{}'.format(second))

Python datetime模塊的使用示例

2、datetime轉為string

# -*- encoding=utf-8 -*-import datetimenow = datetime.datetime.now()print(’type:{}’.format(type(now)))print(’now datetime:{}’.format(now))now_string = now.strftime(’%Y-%m-%d %H:%M:%S’)print(’type:{}’.format(type(now_string)))print(’now string:{}’.format(now_string))

Python datetime模塊的使用示例

3、string轉為datetime

# -*- encoding=utf-8 -*-import datetimetime_str = ’2021-01-28 10:51:26’time_date = datetime.datetime.strptime(time_str, ’%Y-%m-%d %H:%M:%S’)print(’type:{}’.format(type(time_date)))print(time_date)

Python datetime模塊的使用示例

4、時間相加

# -*- encoding=utf-8 -*-import datetimetime_str = ’2021-01-28 10:00:00’time_date = datetime.datetime.strptime(time_str, ’%Y-%m-%d %H:%M:%S’)print(’原始時間:tttt{}’.format(time_date))add_info = datetime.timedelta(days=1, hours=2, minutes=3, seconds=4)add_end = time_date + add_infoprint(’加上1天2個小時3分鐘4秒后:t{}’.format(add_end))

Python datetime模塊的使用示例

5、時間相減

①兩個時間差

# -*- encoding=utf-8 -*-import datetimetime_str = ’2021-01-28 10:00:00’time_date = datetime.datetime.strptime(time_str, ’%Y-%m-%d %H:%M:%S’)print(’原始時間:t{}’.format(time_date))time_str = ’2021-05-29 12:12:12’time_date2 = datetime.datetime.strptime(time_str, ’%Y-%m-%d %H:%M:%S’)print(’原始時間2:t{}’.format(time_date2))time_date3 = time_date2 - time_dateprint(’時間差:{}’.format(time_date3))

Python datetime模塊的使用示例

②減去1天2個小時3分鐘4秒(加負數)

# -*- encoding=utf-8 -*-import datetimetime_str = ’2021-01-28 10:00:00’time_date = datetime.datetime.strptime(time_str, ’%Y-%m-%d %H:%M:%S’)print(’原始時間:tttt{}’.format(time_date))add_info = datetime.timedelta(days=-1, hours=-2, minutes=-3, seconds=-4)add_end = time_date + add_infoprint(’減去1天2個小時3分鐘4秒后:t{}’.format(add_end))

Python datetime模塊的使用示例

以上就是Python datetime模塊的使用示例的詳細內容,更多關于Python datetime模塊的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 亚洲欧美视频 | 日韩精品久久久久久 | 99国内精品 | 国产精品1区 | 91久久精品| 在线不卡视频 | 99热在线观看精品 | 精品在线一区二区 | 欧美视频在线免费 | 免费久 | 成人av网页| 91精品国产91久久久久久吃药 | 毛片一级片 | www国产精品 | 国产成人99久久亚洲综合精品 | 激情五月婷婷 | 日本偷偷操 | 色免费在线视频 | 国产一级片久久久 | 欧美一级欧美三级在线观看 | 日韩欧美国产一区二区 | 国产专区在线 | 国产成人精品综合 | 91精品国产一区 | 国产成人精品一区二区三 | 中文字幕 欧美 日韩 | 亚洲精品99| 一二三四av | 69精品久久久久久 | 四虎永久免费在线 | a级性视频 | 日韩一区二区三区在线视频 | 日本在线播放一区二区 | 精品欧美一区免费观看α√ | 国产精品一区二区免费看 | 野狼在线社区2017入口 | 亚洲精品一区二区在线观看 | 成人免费观看网站 | www.久久99| 国产91久久久久久久免费 | 免费视频久久 |