首页 / PYTHON / python 时间转换
python 时间转换
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python 时间转换,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1500字,纯文字阅读大概需要3分钟。
内容图文
![python 时间转换](/upload/InfoBanner/zyjiaocheng/741/9bc173ca30c444a9a85e9dcb84b4daf0.jpg)
#
# 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)
内容总结
以上是互联网集市为您收集整理的python 时间转换全部内容,希望文章能够帮你解决python 时间转换所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。