Chinaunix

标题: python日期转换的问题 [打印本页]

作者: phpbird    时间: 2006-04-13 14:40
标题: python日期转换的问题
如:4月6日14点25分
怎么转换成:2006-04-06 14:25:00?

怎么转换好?
作者: phpbird    时间: 2006-04-13 15:07
又是自己找到了。。。
>>> time.strptime("2002年2月2","%Y年%m月%d")
(2002, 2, 2, 0, 0, 0, 5, 33, -1)
再判断一下年就可以了。。
作者: happygg    时间: 2006-04-14 12:15
还有时间啊,怎么转换
作者: phpbird    时间: 2006-04-14 14:40
一样的阿,后边加上相应的格式就可以了。
作者: 吕不为    时间: 2006-04-15 22:55
e-- 受不了了。
import time
print time.strftime('%Y年%m月%d日 %H点%M分%S秒',time.localtime())
作者: happygg    时间: 2006-04-17 09:16
呵呵,不好意思,我刚接触python3天,只看到了一些基本的语法,对于方法,我知道的不多,有没有好的教程推荐啊?
作者: 九佰    时间: 2006-04-17 09:59
happygg  去看置定的帖子,里面有很多资源。
欢迎进入python的世界~~!
作者: happygg    时间: 2006-04-17 13:15
谢谢楼上,我去看看
作者: gashero    时间: 2006-05-03 10:53
time模块中有一个函数mktime是从TimeTuple转换到滴答值的。TimeTuple共有9个元素,分别是年月日,时分秒,然后还有三个无聊的参数,可以用如下来生成。
import time
t=time.mktime((2006,4,6,14,25,0,0,0,0))
之后的t就是一个Python内部时间变量了,可以对他进行很好的格式化和输出。
至于格式化输出,如上几位说的很好。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2