Python time mktime()方法

栏目: 编程语言 · Python · 编程教程 · python 教程 · 发布时间: 8年前

内容简介:Python time mktime() 函数执行与gmtime(), localtime()相反的操作,它接收struct_time对象作为参数,返回用秒数来表示时间的浮点数。

描述

Python time mktime() 函数执行与gmtime(), localtime()相反的操作,它接收struct_time对象作为参数,返回用秒数来表示时间的浮点数。

如果输入的值不是一个合法的时间,将触发 OverflowError 或 ValueError。

语法

mktime()方法语法:

time.mktime(t)

参数

  • t -- 结构化的时间或者完整的9位元组元素。

返回值

返回用秒数来表示时间的浮点数。

实例

以下实例展示了 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 2009

以上所述就是小编给大家介绍的《Python time mktime()方法》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Pro HTML5 Programming

Pro HTML5 Programming

Peter Lubbers、Brian Albers、Frank Salim / Apress / 2010-9-1 / USD 49.99

HTML5 is here, and with it, web applications take on a power, ease, scalability, and responsiveness like never before. In this book, developers will learn how to use the latest cutting-edge HTML5 web ......一起来看看 《Pro HTML5 Programming》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具