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操作json文件获取内容

这篇文章主要介绍了如何基于python操作json文件获取内容,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 写case时,将case...

django使用django-apscheduler 实现定时任务的例子

下载: pip install apscheduler pip install django-apscheduler 将 django-apscheduler 加到项目中settings...

Python 比较两个数组的元素的异同方法

通过set()获取两个数组的交/并/差集: print set(a).intersection(set(b)) # 交集 print set(a).union(set(b)) # 并...

pandas将多个dataframe以多个sheet的形式保存到一个excel文件中

要实现这个功能,可能有多种方法,我在这里记录下一个比较方便的方法: import pandas as pd writer = pd.ExcelWriter('test.xlsx')...

pandas read_excel()和to_excel()函数解析

前言 数据分析时候,需要将数据进行加载和存储,本文主要介绍和excel的交互。 read_excel() 加载函数为read_excel(),其具体参数如下。 read_exce...