import time

1. time.gmtime()       显示当前structtime,格林时间

>>> import time
>>> time.gmtime()
time.struct_time(tm_year=2016, tm_mon=3, tm_mday=13, tm_hour=12, tm_min=48, tm_s
ec=25, tm_wday=6, tm_yday=73, tm_isdst=0)
>>> a = time.gmtime()
>>> print(a.tm_year)
2016

2.  time.localtime()    显示当前本地时间,structime

>>> time.localtime()
time.struct_time(tm_year=2016, tm_mon=3, tm_mday=13, tm_hour=20, tm_min=51, tm_s
ec=35, tm_wday=6, tm_yday=73, tm_isdst=0)

3. time.time()    当前系统时间戳,以毫秒为单位的时间,从1970年到现在

>>> time.time()
1457873653.96087

4. time.strftime("%Y-%m-%d %H:%M:%S")     将strucktime格式化输出

>>> time.strftime("%Y-%m-%d %H:%M:%S")
'2016-03-13 20:58:49'
>>> time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
'2016-03-13 13:05:55'

5. time.mktime()    将strucktime变成时间戳

>>> time.mktime(time.localtime())
1457874273.0
>>>

6. time.strptime()     转换成strucktime格式

>>> time.strptime("2015-04-03", "%Y-%m-%d")
time.struct_time(tm_year=2015, tm_mon=4, tm_mday=3, tm_hour=0, tm_min=0, tm_sec=
0, tm_wday=4, tm_yday=93, tm_isdst=-1)

7. time.ctime()    系统格式输出当前系统时间,也可用于将时间戳转换成系统格式

>>> time.ctime()
'Sun Mar 13 21:10:58 2016'
>>> time.ctime(1457874763.685563)
'Sun Mar 13 21:12:43 2016'

python(5) - time模块的更多相关文章

  1. python之platform模块

    python之platform模块 ^_^第三个模块从天而降喽!! 函数列表 platform.system() 获取操作系统类型,windows.linux等 platform.platform() ...

  2. python之OS模块详解

    python之OS模块详解 ^_^,步入第二个模块世界----->OS 常见函数列表 os.sep:取代操作系统特定的路径分隔符 os.name:指示你正在使用的工作平台.比如对于Windows ...

  3. python之sys模块详解

    python之sys模块详解 sys模块功能多,我们这里介绍一些比较实用的功能,相信你会喜欢的,和我一起走进python的模块吧! sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传 ...

  4. 学习PYTHON之路, DAY 6 - PYTHON 基础 6 (模块)

    一 安装,导入模块 安装: pip3 install 模块名称 导入: import module from module.xx.xx import xx from module.xx.xx impo ...

  5. linux下python调用c模块

    在C调用Python模块时需要初始化Python解释器,导入模块等,但Python调用C模块却比较简单,下面还是以helloWorld.c 和 main.py 做一说明:   (1)编写C代码,hel ...

  6. Python学习之模块进程函数详解

    今天在看<Beginning Linux Programming>中的进程相关部分,讲到Linux几个进程相关的系统函数: system , exec , fork ,wait . Pyt ...

  7. python基础——第三方模块

    python基础——第三方模块 在Python中,安装第三方模块,是通过包管理工具pip完成的.  如果你正在使用Mac或Linux,安装pip本身这个步骤就可以跳过了.  如果你正在使用Window ...

  8. python基础——使用模块

    python基础——使用模块 Python本身就内置了很多非常有用的模块,只要安装完毕,这些模块就可以立刻使用. 我们以内建的sys模块为例,编写一个hello的模块: #!/usr/bin/env ...

  9. python 中time模块使用

    在开始之前,首先要说明这几点: 1.在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主 ...

  10. Python之logging模块

    一.引言 之前在写一些小程序的时候想把日志内容打到文件中,所以就自己写了一个logger.py的程序,如下: #!/usr/bin/python # -*- coding=utf-8 -*- impo ...

随机推荐

  1. B树在数据库索引中的应用剖析

    引言 关于数据库索引,google一个oracle index,mysql index总 有大量的结果,其中很多的使用方法推荐,**索引之n条经典建议云云.笔者认为,较之借鉴,在搞清楚了自己的需求的基 ...

  2. StringReplace用法

    来自:http://www.aspww.cn/View/12022801.aspx ---------------------------------------------------------- ...

  3. thymeleaf条件表达式

    条件表达式形式:condition, then and else <tr th:class="${row.even}? 'even' : 'odd'"> ... < ...

  4. Python模块(Module)

    一个Python Module(模块),是一个文件,包含了Python对象定义和Python语句(definitions and statements).文件名就是模块名加上后缀.py,在模块内部,模 ...

  5. AVCaptureSession 照相时获取 AVCaptureVideoPreviewLayer尺寸

    http://stackoverflow.com/questions/14153878/avcapturesession-preset-photo-and-avcapturevideopreviewl ...

  6. HDU 3790 最短路径问题 (最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3790 简单的最短路问题,这题听说有重边.我用spfa和dijkstra写了一遍,没判重边,速度都差不多 ...

  7. Unity3D之UGUI学习笔记(一):UGUI介绍以及Canvas

    UGUI是Unity3D4.6官方提供的UI系统,支持2D和3D UI的开发. Unity3D UI史 OnGUI 在Unity4.6之前,官方提供的是OnGUI函数来开发UI界面,当然问题也比较多, ...

  8. arcgis下载

    你懂的~ t.cn/RA4cc3k 密码ygdr 包含10.2全部,含有(亲测)字样表示测试过OK的,SP是从esri网站下载的几乎全部patch和sp,包括desktop.engine和sever: ...

  9. window.open()打开窗口的几种方式

    1. window.open("http://www.baidu.com/", "_search");//在一个新的窗口打开百度,并且使URL地址出现在搜索栏中 ...

  10. PostgreSQL的 initdb 源代码分析之二十一

    继续分析: setup_schema(); 展开: 实质就是创建info_schema. cmd 是: "/home/pgsql/project/bin/postgres" --s ...