在Python中操作时间之mktime()方法的使用教程

WBOY
Release: 2016-06-06 11:17:12
Original
1401 people have browsed it

mktime()方法是localtime()反函数。它的参数是struct_time或全9元组,它返回一个浮点数,为了兼容时time()。

如果输入值不能表示为有效的时间,那么OverflowError或ValueError错误将被引发。
Syntax

以下是mktime()方法的语法:

time.mktime(t)
Copy after login

参数

  • 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))
Copy after login

当我们运行上面的程序,它会产生以下结果:

time.mktime(t) : 1234915418.000000 asctime(localtime(secs)): Tue Feb 17 17:03:38 2014
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!