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

yipeiwu_com7年前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黑魔法@property装饰器的使用技巧解析

@property有什么用呢?表面看来,就是将一个方法用属性的方式来访问. 上代码,代码最清晰了. class Circle(object): def __init__...

python 以16进制打印输出的方法

打印整数16进制 num=10 print('%#x'%num) 打印字符串中的16进制 arr='12342535' for i in arr: print('%#x'%o...

python类继承用法实例分析

本文实例讲述了python类继承用法。分享给大家供大家参考。具体方法如下: #!/usr/bin/python # Filename: inherit.py class Schoo...

Python的collections模块中namedtuple结构使用示例

namedtuple 就是命名的 tuple,比较像 C 语言中 struct。一般情况下的 tuple 是 (item1, item2, item3,...),所有的 item 都只能...

python判断计算机是否有网络连接的实例

先安装第三方库:pip install requests def isConnected(): import requests try: html = request...