ChinaUnix.net
相关文章推荐:

python 时间戳 转换

src = "2008-11-12 10:33:33" temp = mktime(re.split("[ :-]",src).extend("000")) print "temp:",temp #re.split("[ :-]",src)是将空格,冒号和横杠作为分隔符,将src按年月日时分秒分为六 #项, extend("000")填上三项,每一项都是0,因为满足mktime()的需要(需要9项),然后 #就将src转换为秒数了 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/80823/showart_1411763.html

by mhz-ada - Python文档中心 - 2008-11-13 10:58:23 阅读(2150) 回复(0)

相关讨论

RT 或者如何将格式化时间 转换时间

by duketang - Python - 2012-09-25 12:20:56 阅读(71169) 回复(4)

今天作加班时间计算,将这个模块整理,升级了一下: [color="#008080"]# encoding:gb2312 [color="#008080"]# [color="#008080"]# revision 2007.04.29 : [color="#008080"]# 正则升级为带组名, [color="#008080"]# 升级局部变量命名规则, [color="#008080"]# 升级itv2time返回值表达式 [color="#008080"]# revision 2007.03.31 : [color="#008080"]# 启动版本, [color="#008080"]# 基本功能实现 [color="#008080"]# you can us...

by wibrst - Python文档中心 - 2007-04-29 17:35:39 阅读(1181) 回复(0)

这个只能转成秒的时间,难道是直接乘以1000就变成毫秒了? time.mktime(time.strptime(a,'%Y-%m-%d %H:%M:%S'))

by liumilan2009 - Python - 2014-05-06 09:36:31 阅读(18986) 回复(3)

本文转自: http://blog.csdn.net/Aarchbishop/archive/2006/04/30/699000.aspx >>> import time >>> import datetime >>> now = time.localtime() >>> now (2006, 4, 30, 18, 7, 35, 6, 120, 0) >>> type(now) >>> 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 将...

by didonglin - Python文档中心 - 2010-02-24 10:11:09 阅读(7244) 回复(1)

本文转自: http://blog.csdn.net/Aarchbishop/archive/2006/04/30/699000.aspx >>> import time >>> import datetime >>> now = time.localtime() >>> now (2006, 4, 30, 18, 7, 35, 6, 120, 0) >>> type(now) >>> 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 将...

by linxh - Python文档中心 - 2007-01-21 21:41:14 阅读(996) 回复(0)

我想计算web日志中两个点击的时间相差多少秒,怎么计算? 时间格式如下所示,怎么转成秒? 30/Jan/2013:21:48:19 31/Jan/2013:12:45:34

by ymc4444 - Python - 2013-04-18 02:53:28 阅读(2139) 回复(1)

1)秒数 ===》字符串 from time import * def secs2str(secs): return strftime("%Y-%m-%d %H:%M:%S",localtime(secs)) 2)字符串 ===》秒数 from time import * 先将时间字符串解析为9元组,例如: 2008-11-25 23:51:20,解析为9元组:[2008,11,25,23,51,20,0,0,0]。 >>> tmlist = [2008,11,25,23,51,20,0,0,0] >>> mktime(tmlist) 1227628280.0 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net...

by zpp71 - Python文档中心 - 2008-11-25 23:50:05 阅读(3092) 回复(0)

如果一次遇到:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 这样的错误,然后到网上找找解决方案可以接受,如果多次遇到这样的问题,那就是自己的问题了。
web开发,数据从各处(如果不明确encode)收集到业务层(指明是utf8)处理,往往会有因各个源字符集不同导致处理失败的情况,就比如上面这个错误。
到网上一看,python字符集的处理大家一致感觉还是挺麻烦的,还是先来看看http://en.wikipedia.org/wiki/Ch...

by chaoxiangliu - Web开发 - 2011-12-23 03:36:43 阅读(1019) 回复(0)

python 包含的模块和函数都非常丰富,但在目前版本里缺找不到十进制到二进制转化的现成函数,看到网友在帖子里发了一个关于二进制转化的小段,把它转过来,顺便也添加一些类似的函数,一起作为学习的笔记: #!/usr/bin/python def bin(x): result = '' x = int(x) while x > 0: mod = x % 2 x /= 2 result = str(mod) + result return res...

by zhaohang3031 - Python文档中心 - 2009-03-22 16:03:17 阅读(1707) 回复(0)

大多数程序都要处理大量类型的信息。但有时,所有操作都针对一种类型进行。例如,一个字符串与另一个字符串相加(连接)所生成的还是一个字符串。但是,经常都需要将一种类型的数据转换或强制(coerce)为另一种类型。这可能发生在赋值和计算过程中。解析器知道怎么在内建类型之间执行特定的转换。程序员可调用恰当的python函数,比如int或float,实现内建类型之间的强制转换。 但用户自定义类又该怎么办呢?解析器不知道怎么在用...

by lvDbing - Python文档中心 - 2008-09-30 12:06:25 阅读(1997) 回复(0)