python 日期转换
字符串转日期
from datetime import datetime
text = '2012-09-20'
y = datetime.strptime(text, '%Y-%m-%d')
print(y)
from datetime import datetime
def parse_ymd(s): #这种方式会快很多
year_s, mon_s, day_s = s.split('-')
return datetime(int(year_s), int(mon_s), int(day_s))
时间戳转日期
timeStamp = 1642431600000/1000
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
print(otherStyleTime)
# 字符类型的时间
tss1 = '2022-01-17 00:00:00'
# 转为时间数组
timeArray = time.strptime(tss1, "%Y-%m-%d %H:%M:%S")
print(timeArray)
# 转为时间戳
timeStamp = int(time.mktime(timeArray))
print(timeStamp) # 1381419600
timeStamp = 1642431600000/1000
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
print(otherStyleTime)
# 一小时差值
print(1642431600000-1642420800000)
python 日期转换相关推荐
- python各种类型日期转换大全
最近写python做各种日期转换比较多,顺便总结一下,先上张图: 1 # 根据字符串类型转日期 返回值类型<class 'time.struct_time'> 2 st_time = ti ...
- Python 日期和时间戳的转换
Python 日期和时间戳的转换 1. Python中处理时间的模块 Python中处理时间的模块有time.datetime和calendar. 在Python中表示时间的方式: 时间戳:10位整数 ...
- python时间戳转换日期格式_Python 日期和时间戳的转换
Python 日期和时间戳的转换 1. Python中处理时间的模块 Python中处理时间的模块有time.datetime和calendar. 在Python中表示时间的方式: 时间戳:10位整数 ...
- python 数字日期转换,格式化时间,日期加减天,小时,分钟
把数字转换成日期格式 例如:数字 202105271354 转换成日期格式 2021-05-27 13:54:00 from dateutil.parser import parset_list1 ...
- Python日期字符串到日期对象
本文翻译自:Python date string to date object How do I convert a string to a date object in python? 如何在pyt ...
- oracle 日期转换成毫秒数,ORACLE:毫秒与日期的相互转换,获取某天的信息
毫秒转换为日期 SELECT TO_CHAR(1406538765000 / (1000 * 60 * 60 * 24) + TO_DATE('1970-01-01 08:00:00', 'YYYY- ...
- python 日期时间处理_如何使用Python处理日期和时间
python 日期时间处理 当试图使事情与datetime模块一起工作时,大多数Python用户在我们诉诸猜测直到错误消失之前都面临着一个问题. datetime是似乎易于使用的API之一,但要求开发 ...
- python美元汇率兑换程序代码_如何实现python汇率转换代码
对于刚刚入门python的学习者们,最头疼的莫过于基础的功能实现代码了,很多函数可以实现意义是一样的,今天小编教大家实例--实现python汇率转换代码. Python中的货币转换器 tkinter ...
- python汇率的转换程序_如何实现python汇率转换代码
对于刚刚入门python的学习者们,最头疼的莫过于基础的功能实现代码了,很多函数可以实现意义是一样的,今天小编教大家实例--实现python汇率转换代码. Python中的货币转换器 tkinter ...
最新文章
- [傅里叶变换及其应用学习笔记] 二十六. 高维傅里叶变换的推导
- 红米airdots掉了怎么查找_红米K30 Pro 荣耀V30pro 这两款手机该怎么选呢?
- android 底部表格布局TableLayout
- mysql用binlog恢复数据_利用mysql的binlog恢复数据
- 小米12系列获3C认证:120W快充终于回归
- CQOI 2016 不同的最小割
- python 代码分块_python大数据分块处理
- Java对象引用之“强引用、软引用、弱引用、虚引用”
- 30个有助于探索Go编程语言的在线资源
- java.lang.NoClassDefFoundError: Could not initialize class org.apache.batik.bridge.CursorManager
- rapidxml往xml文件循环写入内容
- 数据挖掘基础学习笔记
- csgo显示连接任何官方服务器失败,csgo连接任意官方服务器失败怎么办_csgo连接官方服务器失败解决方法...
- 初中英语语法(009)-动名词
- BUUCTF:[ACTF新生赛2020]swp
- PB 切换中英文输入法
- JDBC报错:The server time zone value is unrecognized or represents more than one time zone 已解决
- 关于wi-fi无线局域网的若干问题
- 数据库和表的基本操作
- Java利用Gzip对字符串进行压缩与解压