在Python中操作时间之mktime()方法的使用教程
2015-05-22 12:09
936 查看
mktime()方法是localtime()反函数。它的参数是struct_time或全9元组,它返回一个浮点数,为了兼容时time()。
如果输入值不能表示为有效的时间,那么OverflowError或ValueError错误将被引发。
Syntax
以下是mktime()方法的语法:
time.mktime(t)
参数
- t -- 这是struct_time或满9元组。
返回值
此方法返回一个浮点数,对于兼容性time()。
例子
下面的例子显示了mktime()方法的使用。
#!/usr/bin/python import time t = (2009, 2, 17, 17, 3, 38, 1, 48, 0) secs = time.mktime( t ) print "time.mktime(t) : %f" % secs print "asctime(localtime(secs)): %s" % time.asctime(time.localtime(secs))
当我们运行上面的程序,它会产生以下结果:
time.mktime(t) : 1234915418.000000 asctime(localtime(secs)): Tue Feb 17 17:03:38 2014
您可能感兴趣的文章:
- python中关于时间和日期函数的常用计算总结(time和datatime)
- python利用datetime模块计算时间差
- Python中实现对Timestamp和Datetime及UTC时间之间的转换
- Python中datetime常用时间处理方法
- Python 时间处理datetime实例
- python使用datetime模块计算各种时间间隔的方法
- Python datetime时间格式化去掉前导0
- 详解python时间模块中的datetime模块
- Python简单格式化时间的方法【strftime函数】
- 浅谈Python中用datetime包进行对时间的一些操作
- python UNIX_TIMESTAMP时间处理方法分析
- Python的时间模块datetime详解
- Python使用time模块实现指定时间触发器示例
相关文章推荐
- 在Python中操作时间之mktime()方法的使用教程
- 在Python中操作时间之tzset()方法的使用教程
- 在Python中操作时间之tzset()方法的使用教程
- 在Python中操作时间之strptime()方法的使用
- Python中用sleep()方法操作时间的教程
- 在Python中操作日期和时间之gmtime()方法的使用
- 在Python操作时间和日期之asctime()方法的使用
- 在Python操作时间和日期之asctime()方法的使用
- 在Python中操作日期和时间之gmtime()方法的使用
- Python中用sleep()方法操作时间的教程
- 在Python中操作时间之strptime()方法的使用
- 在Python中操作文件之seek()方法的使用教程
- 在Python中操作文件之read()方法的使用教程
- 在Python中使用next()方法操作文件的教程
- 在Python程序中操作文件之isatty()方法的使用教程
- 在Python程序中操作文件之flush()方法的使用教程
- 在Python程序中操作文件之flush()方法的使用教程
- 在Python程序中操作文件之isatty()方法的使用教程
- 在Python中使用next()方法操作文件的教程
- 在Python中操作文件之read()方法的使用教程