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. webSocket vnc rfb

  2. 转载-清除Linux中MySQL的使用痕迹~/.mysql_history

    原文地址:清除Linux中MySQL的使用痕迹~/.mysql_history 作者:RogerZhuo 原贴:http://bbs.chinaunix.net/thread-3676498-1-1. ...

  3. Codeforces 602B Approximating a Constant Range(想法题)

    B. Approximating a Constant Range When Xellos was doing a practice course in university, he once had ...

  4. STL学习系列六:List容器

    List简介 list是一个双向链表容器,可高效地进行插入删除元素. list不可以随机存取元素,所以不支持at.(pos)函数与[]操作符.it++(ok), it+5(err) #include ...

  5. HDU 5723 Abandoned country (最小生成树+dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5723 n个村庄m条双向路,从中要选一些路重建使得村庄直接或间接相连且花费最少,这个问题就是很明显的求最 ...

  6. BNU 51276 - 道路修建 Small (并查集)

    题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=51276 具体题意不描述了,一眼看过去就是并查集,关键是添加边以后更新答案.我是开个二维的数组an ...

  7. PsLookupProcessByProcessId分析

    本文是在讨论枚举进程的时候产生的,枚举进程有很多方法,Ring3就是ZwQuerySystemInformation(),传入SysProcessesAndThreadsInformation这个宏, ...

  8. C++中不常用关键字

    mutable关键字 关键字mutable是C++中一个不常用的关键字,他只能用于类的非静态和非常量数据成员.我们知道一个对象的状态由该对象的非静态数据成员决定,所以随着数据成员的改变,对像的状态也会 ...

  9. 配置 dovecat 的 log

    关于 dovecot 的日志配置,请检查 conf.d/10-logging.conf 文件, 特别需要提示的是将 错误/信息 文件分开保存,建议分别设置 log_path / info_log_pa ...

  10. my-view-isnt-reflecting-changes-ive-made-to-the-underlying-tables

    FROM http://sqlstudies.com/2013/01/20/my-view-isnt-reflecting-changes-ive-made-to-the-underlying-tab ...