python 时间处理
来源:互联网 发布:淘宝宝贝排名下降 编辑:程序博客网 时间:2024/06/05 11:55
import
time,datetime
# date to str
print
time.strftime(
"%Y-%m-%d %X"
, time.localtime())
#str to date
t
=
time.strptime(
"2009 - 08 - 08"
,
"%Y - %m - %d"
)
print(time.mktime(t)) #转换为秒值
y,m,d
=
t[
0
:
3
]
print
datetime.datetime(y,m,d)
2015
-
05
-
13
10
:
43
:
07
2009
-
08
-
08
00
:
00
:
00
#!/usr/bin/env python
# -*- coding: cp936 -*-
import time
import datetime
def ISOString2Time( s ):
'''
convert a ISO format time to second
from:2006-04-12 16:46:40 to:23123123
把一个时间转化为秒
'''
d=datetime.datetime.strptime(s,"%Y-%m-%d %H:%M:%S")
return time.mktime(d.timetuple())
def Time2ISOString( s ):
'''
convert second to a ISO format time
from: 23123123 to: 2006-04-12 16:46:40
把给定的秒转化为定义的格式
'''
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime( float(s) ) )
if __name__ == '__main__':
a="2013-08-26 16:58:00"
b=ISOString2Time(a)
print b
c=Time2ISOString(b)
print c
运行结果:
1377507480.0
2013-08-26 16:58:00
0 0
- python datetime时间处理
- Python 时间处理
- python 时间处理
- python datetime处理时间
- python UNIX_TIMESTAMP时间处理
- python datetime处理时间
- python时间处理函数
- A005:python 时间处理
- python 时间戳处理
- python 时间戳处理
- python 时间处理
- python 时间处理
- python datetime处理时间
- python datetime处理时间
- python处理时间
- python-时间处理问题
- Python 时间处理
- python 时间处理
- 程序员修炼之道摘要
- Count Complete Tree Nodes (求完全二叉树节点树)
- 快速排序算法
- httpclient客户端thread+handler+message(get)
- linux awk命令详解
- python 时间处理
- 选择点
- laravel部署在nginx 出现 nginx 403 forbidden 错误的处理
- 关于hadoop无法启动的问题
- 呼叫保持
- Ubuntu下和VirtualBox建立ssh无密码访问问题
- 《猜猜看》游戏开发
- 试图控制器的生命周期 加载过程
- gnumpy plus cudamat