时间三种形式:

1.timestamp   从1970-1-1 00:00到现在经历的秒数

2.string_time   Sat Mar 28 22:24:24 2009

3.struct_time  时间为9个元素的数组

year (four digits, e.g. 1998)
    month (1-12)
    day (1-31)
    hours (0-23)
    minutes (0-59)
    seconds (0-59)
    weekday (0-6, Monday is 0)
    Julian day (day in the year, 1-366)
    DST (Daylight Savings Time) flag (-1, 0 or 1) 是否是夏令时

经常用的函数:

1. asctime([tuple]) --> string_time      ##将stuct_time转化为string_time,默认当前时间

time.asctime()   ##将当前时间转化为string_time

time.asctime((1989,01,01,8,8,1,0,4,0))   ##后面那三位对结果好像没有影响

2.ctime([seconds]) --> string_time           ##将timestamp转化为string_time,默认当前时间

time.ctime()     ##将当前时间转化为string_time

time.ctime(123123123.1)  ##将这个时间戳的时间转化为string_time

3.gmtime([seconds]) --> struct_time  ##将timestamp转化为UTC时区(0时区)的struct_time

time.gmtime()

time.gmtime(123123123)

4.localtime([seconds])  --> struct_time  ##将timestamp转化为当前时区的struct_time

time.localtime()

time.localtime(123123123)

5.mktime(tuple) --> stamptime             ##将struct_time转化为stamptime

time.mktime((1973, 11, 26, 8, 52, 3, 0, 330, 0))  ##与localtime相反

6.strftime(format[,struct_time]) --> string_time   ##将struct_time通过格式符转化为string_time

%y 两位数的年份表示(00-99)
  %Y 四位数的年份表示(000-9999)
  %m 月份(01-12)
  %d 月内中的一天(0-31)
  %H 24小时制小时数(0-23)
  %I 12小时制小时数(01-12) 
  %M 分钟数(00=59)
  %S 秒(00-59)

%a 本地简化星期名称
  %A 本地完整星期名称
  %b 本地简化的月份名称
  %B 本地完整的月份名称
  %c 本地相应的日期表示和时间表示
  %j 年内的一天(001-366)
  %p 本地A.M.或P.M.的等价符
  %U 一年中的星期数(00-53)星期天为星期的开始
  %w 星期(0-6),星期天为星期的开始
  %W 一年中的星期数(00-53)星期一为星期的开始
  %x 本地相应的日期表示
  %X 本地相应的时间表示
  %Z 当前时区的名称
  %% %号本身

time.strftime('%Y-%m-%d')

time.strftime('%Y-%m-%d %H-%M-%S',(1973, 11, 26, 8, 52, 3, 0, 330, 0))

7.strptime(string, format) -> struct_time  ##string_time根据格式化符转化为struct_time

time.strptime('2013-09-09','%Y-%m-%d')

8.sleep          ##睡几秒,也就是暂停几秒

time.sleep(10)          ##睡10秒

9.time     --> ##返回到今天的StampTime,不接受参数

time.time()

转化图:

time模块学习的更多相关文章

  1. Day5 - Python基础5 常用模块学习

    Python 之路 Day5 - 常用模块学习   本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shel ...

  2. # nodejs模块学习: express 解析

    # nodejs模块学习: express 解析 nodejs 发展很快,从 npm 上面的包托管数量就可以看出来.不过从另一方面来看,也是反映了 nodejs 的基础不稳固,需要开发者创造大量的轮子 ...

  3. 【转】Python模块学习 - fnmatch & glob

    [转]Python模块学习 - fnmatch & glob 介绍 fnmatch 和 glob 模块都是用来做字符串匹配文件名的标准库. fnmatch模块 大部分情况下使用字符串匹配查找特 ...

  4. pythone函数基础(7)第三方模块学习

    一,time模块学习 import time # print(int(time.time()))#时间戳# res = time.strftime('%Y-%m-%d %H:%M:%S')#取当前格式 ...

  5. python中confIgparser模块学习

    python中configparser模块学习 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section ...

  6. Python logging 模块学习

    logging example Level When it's used Numeric value DEBUG Detailed information, typically of interest ...

  7. python - argparse 模块学习

    python - argparse 模块学习 设置一个解析器 使用argparse的第一步就是创建一个解析器对象,并告诉它将会有些什么参数.那么当你的程序运行时,该解析器就可以用于处理命令行参数. 解 ...

  8. Python 日期时间处理模块学习笔记

    来自:标点符的<Python 日期时间处理模块学习笔记> Python的时间处理模块在日常的使用中用的不是非常的多,但是使用的时候基本上都是要查资料,还是有些麻烦的,梳理下,便于以后方便的 ...

  9. 审计系统---paramiko模块学习

    paramiko模块学习 [更多参考]http://www.cnblogs.com/wupeiqi/articles/4963027.html [paramiko的Demo实例]https://git ...

  10. day5模块学习 -- time、datetime时间模块

    1.定义 模块:用来从逻辑上组织python(变量,函数,类,逻辑:实现一个功能)代码,本质就是.py结尾的python文件(文件名:test.py,对应的模块名test) 包:用来从逻辑上组织模块的 ...

随机推荐

  1. [英语学习]国外的在线广播网站,类似喜马拉雅和荔枝FM

    今天在Seattle Art  Museum 网站上看东西,发现了这个好网站. 主要是外文资料,可以练听力,也可以找到<我爱吕西安>的英文版本. https://soundcloud.co ...

  2. pycharm 皮肤主题及个性化设置

    1.设置IDE皮肤主题 File -> Settings -> IDE Settings -> Appearance -> Theme -> 选择“Alloy.IDEA ...

  3. CodeIgniter 发送邮件

    1. 在config目录中增加email.php $config['charset'] = 'utf-8'; $config['wordwrap'] = TRUE; $config['protocol ...

  4. 【IOS笔记】Windows

    Windows Every iOS application needs at least one window—an instance of the UIWindow class—and some m ...

  5. Xamarin Visual Studio无法debug

    在Visual Studio中,Target IOS Device下拉框是禁用状态,无法选择. Xamarin论坛中有不少关于这个问题的,如下面这个帖子: http://forums.xamarin. ...

  6. Nobel Lecture, December 12, 1929 Thermionic phenomena and the laws which govern them

    http://www.nobelprize.org/nobel_prizes/physics/laureates/1928/richardson-lecture.pdf OWEN W. RICHARD ...

  7. GenderGuesser

    http://www.hackerfactor.com/GenderGuesser.php#Analyze

  8. [转]EF 4.1 Code First

    这篇文章介绍Code First开发以及如何与DbContext API一起使用.Code First允许使用C#或VB.NET类定义模型,在类或属性上有选择性的执行额外的配置或者使用Fluent A ...

  9. Delphi格式化输出函数(1): Format

    vars: string;begin//指令类型 types := Format('最大整数是: %d; 最小整数是: %d',[MaxInt,Low(Integer)]);//返回: 最大整数是: ...

  10. 【转】Xamarin.Android 入门之:Xamarin+vs2015 环境搭建

    Xamarin.Android 入门之:Xamarin+vs2015 环境搭建   一.前言 此篇博客主要写了如何使用搭建xamarin开发的环境,防止我自己万一哪天电脑重装系统了,可以直接看这篇博客 ...