Python中的localtime()方法使用详解

yipeiwu_com5年前Python基础

 localtime()方法类似gmtime()方法,但它转换秒数为本地时间。如果不设置秒时或None,所返回的当前时间使用time()方法。在dst标志被设置为1时,夏令时适用于给定的时间。
语法

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

time.localtime([ sec ])

参数

  •     sec -- 这是秒数转换成结构struct_time来表示。

返回值

此方法不返回任何值。
例子

下面的例子显示了localtime()方法的使用。

#!/usr/bin/python
import time

print "time.localtime() : %s" % time.localtime()

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

time.localtime() : (2009, 2, 17, 17, 3, 38, 1, 48, 0)

相关文章

决策树剪枝算法的python实现方法详解

决策树剪枝算法的python实现方法详解

本文实例讲述了决策树剪枝算法的python实现方法。分享给大家供大家参考,具体如下: 决策树是一种依托决策而建立起来的一种树。在机器学习中,决策树是一种预测模型,代表的是一种对象属性与...

python 从csv读数据到mysql的实例

如下所示: import csv import sys,os import MySQLdb def read_csv(filename): with open(filename...

PyQt编程之如何在屏幕中央显示窗体的实例

这几天在学习PyQt编程,用CSDN来记录一下学过的东西,免得以后忘记了大笑 import sys from PyQt4 import QtGui #导入控件模块 class C...

python寻找list中最大值、最小值并返回其所在位置的方法

实例如下所示: c = [-10,-5,0,5,3,10,15,-20,25] print c.index(min(c)) # 返回最小值 print c.index(max(c)...

python实现转圈打印矩阵

本文实例为大家分享了python实现转圈打印矩阵的具体代码,供大家参考,具体内容如下 #! conding:utf-8 __author__ = "hotpot" __date__...