关于Python中时间与字符串直接的转换
来源:互联网 发布:淘宝怎么批量发货 编辑:程序博客网 时间:2024/05/16 05:07
>>> import time
>>> import datetime
>>> now = time.localtime()
>>> now
(2006, 4, 30, 18, 7, 35, 6, 120, 0)
>>> type(now)
<type 'time.struct_time'>
>>> str_now = time.strftime("%m/%d/%Y %X", now )
>>> str_now
'04/30/2006 18:07:35'
>>> new_now = time.strptime( str_now, "%m/%d/%Y %X" )
>>> new_now
(2006, 4, 30, 18, 7, 35, 6, 120, -1)
这里,strftime 将 struct_time 的时间按指定的格式转化成 字符串
strptime 将 字符串按指定的格式转化成 struct_time 的时间
struct_time 的时间没有现成的比较的函数,可以将 struct_time 转化成 datetime.datetime
>>> d_now = datetime.datetime( *now[:6] )
>>> type(d_now)
<type 'datetime.datetime'>
>>> d_now
datetime.datetime(2006, 4, 30, 18, 7, 35)
- 关于Python中时间与字符串直接的转换...
- 关于Python中时间与字符串直接的转换
- python时间与字符串之间的转换
- 关于jackson中时间字符串的转换
- Python中时间戳与时间字符串相互转换
- oracle中字符串与时间的转换
- iOS中字符串时间与时间戳的相互转换
- 时间与字符串的转换
- 字符串与时间的转换
- java计时中字符串时间与秒的转换
- java中字符串与时间转换
- Mysql中关于时间戳与日期的转换
- Python时间戳与时间字符串互相转换实例代码
- Python时间戳与时间字符串互相转换
- python中字符串与datetime的相互转换
- Android中关于字符串与颜色的转换问题
- 在Js(Jquery)中,字符串与JSON格式互相转换的示例(直接运行例子)
- Python 中 字符串与字典间转换
- 静态库和共享库(二)
- 递归创建目录
- 使用命名管道传输对象
- 傻瓜
- 打开管理员账号和关闭
- 关于Python中时间与字符串直接的转换
- 用javaScript制作网页中显示列表
- Axure 学习
- iframe 自动适应页面高度
- ASP调用存储过程:只返回单一记录集的存储过程
- 开始折腾omnipeek
- linux下网卡网络流量监控工具
- ASP调用存储过程:有输入参数和输出参数的存储过程
- 使用VB.NET加快代码开发速度