程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

python 时间转换

发布于2019-08-05 11:51     阅读(741)     评论(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黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

2 0
收藏该文
已收藏

评论内容:(最多支持255个字符)