发布于2019-08-05 11:51 阅读(889) 评论(0) 点赞(2) 收藏(4)
#
# import datetime
# from datetime import datetime
# import time
#
# now_time = datetime.now()
# # now:2019-07-31 15:05:54.306301
# print('now:{0}'.format(datetime.now()))
#
# # 当前的日期
# # now day:2019-07-31
# print('now day:{0}'.format(now_time.date()))
#
# # 当前的时间
# # now time:15:07:54.550967
# print('now time:{0}'.format(now_time.time()))
#
# # 当前年份
# # now year:2019
# print('now year:{0}'.format(now_time.year))
#
# # 当前月份
# # now month:7
# print('now month:{0}'.format(now_time.month))
#
# # 当前日期
# # now day:31
# print('now day:{0}'.format(now_time.day))
#
#
# # 1564557243.8810754 获取到毫秒
# print(time.time())
from datetime import datetime,date,time,timedelta
# 自定义日期和时间
# d = datetime(2020,10,30,14,5)
# # 2020-10-30 14:05:00
# print(d)
#
# d2 = date(2019,3,23)
# # 2019-03-23
# print(d2)
#
# t = time(9,0)
# # 09:00:00
# print(t)
print('---------------------------------')
# # 日期 时间 字符串之间的相互转换
# ds = '2018-10-3 13:42:09'
# ds_t = datetime.strptime(ds, '%Y-%m-%d %H:%M:%S')
# # 9
# print(ds_t.second)
# print('---------------------------------')
# # datetime对象转换成字符串
# n = datetime.now()
# n_str = n.strftime('%Y-%m-%d %H:%M:%S')
# # 2019-07-31 15:32:21
# print(n_str)
# print('---------------------------------')
# # datetime对象 加减操作
# n = datetime.now()
# # 2019-07-31 15:37:15.269619
# print(n)
# n_next = n + timedelta(days = 5, hours = 42)
# # 2019-08-07 09:37:15.269619
# print(n_next)
# 时间的减法
d1 = datetime(2018,10,15)
d2 = datetime(2018,11,12)
rest = d2 - d1
print(dir(rest))
# 28 相差天数
print(rest.days)
作者:我下面给你吃
链接:https://www.pythonheidong.com/blog/article/4439/5cf4c0d9abc3be6ef644/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!