发布于2020-03-18 10:59 阅读(1508) 评论(0) 点赞(12) 收藏(1)
- import time
- times = time.time()
- print("现在时间戳: %0.2f" %times)
-
- localtimes = time.localtime(times)
- print("本地时间是:",localtimes)
- # 将时间戳格式化
- asctime1=time.asctime(localtimes)
- print("格式化时间1:",asctime1)
- print(time.ctime())
-
- formatTime=time.strftime('%Y-%m-%d %H-%M-%S',localtimes)
- print("格式化时间2:",formatTime)
- # 将格式字符串转换为时间戳
- print(time.mktime(time.strptime(asctime1,"%a %b %d %H:%M:%S %Y")))
- 现在时间戳: 1584411264.85
- 本地时间是: time.struct_time(tm_year=2020, tm_mon=3, tm_mday=17, tm_hour=10, tm_min=14, tm_sec=24, tm_wday=1, tm_yday=77, tm_isdst=0)
- 格式化时间1: Tue Mar 17 10:14:24 2020
- Tue Mar 17 10:14:24 2020
- 格式化时间2: 2020-03-17 10-14-24
- import datetime
- today=datetime.date.today()
- oneday=datetime.timedelta(days=1)
- yesterday=today-oneday
- tomorrow=today+oneday
- print(today)
- print(oneday)
- print(yesterday)
- print(tomorrow)
- 2020-03-17
- 1 day, 0:00:00
- 2020-03-16
- 2020-03-18
- import calendar
- cal = calendar.month(2020, 3)
- print("以下输出2020年3月份的日历:")
- print(cal)
- 以下输出2020年3月份的日历:
- March 2020
- Mo Tu We Th Fr Sa Su
- 1
- 2 3 4 5 6 7 8
- 9 10 11 12 13 14 15
- 16 17 18 19 20 21 22
- 23 24 25 26 27 28 29
- 30 31
- import calendar
- cal = calendar.isleap(2020)
- print("判断2020是否是闰年:",cal)
判断2020是否是闰年: True
原文链接:https://blog.csdn.net/jt_121217/article/details/104915835
作者:dfd323
链接:https://www.pythonheidong.com/blog/article/265218/c384e913fa3c22f5c7ce/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!