Python中用sleep()方法操作时间的教程

yipeiwu_com6年前Python基础

 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实现中文输出的两种方法

本文实例讲述了python实现中文输出的两种方法。分享给大家供大家参考。具体如下: 方法一: 用encode和decode 如: import os.path import xlrd...

Python中用startswith()函数判断字符串开头的教程

函数:startswith() 作用:判断字符串是否以指定字符或子字符串开头 一、函数说明 语法:string.startswith(str, beg=0,end=len(string)...

Python实现中一次读取多个值的方法

Python实现中一次读取多个值的方法

Python 2里面读取输入的函数是raw_input(), Python 3的是input(),读入一个值后回车读取输入就退出了,想要一次读取多个输入,可以像下面这样: a, b...

python os.path.isfile 的使用误区详解

下列这几条语句,看出什么问题了不? for file in os.listdir(path): if os.path.isfile(file) and os.path.spl...

python实现用户登陆邮件通知的方法

本文实例讲述了python实现用户登陆邮件通知的方法。分享给大家供大家参考。具体如下: 这里写在linux计划任务里定时执行,当有新用户登陆时候发送用户名到指定邮箱通知管理员。 #!...