在Python中,常用的表示方式的时间有:时间戳,字符串时间,元组时间(既年,月,日,时,分,秒,周几,一年中的第几天,时区)
 
 
time模块:
 
  time.timezone: 获取当前标准时区和UTC时间的差值,单位是秒
 
  time.altzone:获取当前DST(夏令时)时区和UTC时间的差值,单位是秒
 
  time.daylight:判断当前是否使用了DST时间,0表示未启动
 
  time.time():获取当前时间戳
 
  time.sleep(x):沉睡几秒
 
  time.gmtime():获取时间戳对应的元祖格式,如果不跟时间戳,那么获取的是当前时间,对应到标准时区的时间(UTC)时间
 
  time.localtime():获取时间戳对应的元祖格式,如果不跟时间戳,那么获取的是当前时间,对应到本地时区的时间
 
  time.mktime():把元祖(结构化的时间)转换为时间戳
 
  time.strftime('%Y%m%d',tuple_time):把元组时间转化为字符串时间
    %Y表示年,%m表示月份,%d表示日,%H表示时间,%M表示分钟,%S表示秒
 
  time.strptime('字符串时间','字符串格式'),把字符串时间以字符串格式转换为对应的元组时间
 
  time.asctime():转换元组为固定的字符串格式。--> 'Wed Mar 29 21:50:44 2017' 默认为当前时间
    %a %b %d %H:%M:%S %Y
 
  time.ctime():转换时间戳为固定的字符串格式。默认为当前时间
 
 
datetime模块
  基于time的高层的封装,包涵两个类date和time
  date只包涵日期,既年月日
  time只包涵时间,即时分秒
  datetime就包涵了 年月日时分秒
 
  datetime.datetime.now() 获取当前时间
  
  datetime.timedelta(+3):该时间用于和datetime.datetime.now()连用,在当前时间的基础上,加减天数
    >>> datetime.datetime.now() + datetime.timedelta(-3)
    datetime.datetime(2017, 3, 26, 22, 2, 0, 183672)
    这里的+3 -3 默认是天数,如果想要计算小时,需要添加关键字 hours = -3
    >>> datetime.datetime.now() + datetime.timedelta(hours=-3)
    datetime.datetime(2017, 3, 29, 19, 3, 30, 854881)
 
  时间的修改:
    通过replce去修改
    >>> a = datetime.datetime.now()
    >>> a.replace(minute=3,hour=2)
    datetime.datetime(2017, 3, 29, 2, 3, 38, 462881)
    >>>
 
 

时间模块(time/date)的更多相关文章

  1. 第三十二节,datetime时间模块

    首先要引入import datetime时间模块 datetime.date.today()模块函数 功能:输出系统年月日输出格式 2016-01-26[无参] 使用方法:datetime.date. ...

  2. 【转】Python之日期与时间处理模块(date和datetime)

    [转]Python之日期与时间处理模块(date和datetime) 本节内容 前言 相关术语的解释 时间的表现形式 time模块 datetime模块 时间格式码 总结 前言 在开发工作中,我们经常 ...

  3. python时间模块-time和datetime

    时间模块 python 中时间表示方法有:时间戳,即从1975年1月1日00:00:00到现在的秒数:格式化后的时间字符串:时间struct_time 元组. struct_time元组中元素主要包括 ...

  4. Python的时间模块小结(转自:不懂真人)

    import datetimeprint time.time() #时间戳 print time.localtime(time.time()) #时间元组 print time.strftime('% ...

  5. 浅谈Python时间模块

    浅谈Python时间模块 今天简单总结了一下Python处理时间和日期方面的模块,主要就是datetime.time.calendar三个模块的使用.希望这篇文章对于学习Python的朋友们有所帮助 ...

  6. python的时间模块

    python有两个重要的时间模块,分别是time和datetime 先看time模块 表示时间的几种方法: 1)时间元组:time.struct_time(tm_year=2016,   tm_mon ...

  7. Python—day17时间模块、系统模块、递推遍历、序列化

    一.time'''时间戳(timestamp):time.time()延迟线程的运行:time.sleep(secs)(指定时间戳下的)当前时区时间:time.localtime([secs])(指定 ...

  8. 【转载】Python日期时间模块datetime详解与Python 日期时间的比较,计算实例代码

    本文转载自脚本之家,源网址为:https://www.jb51.net/article/147429.htm 一.Python中日期时间模块datetime介绍 (一).datetime模块中包含如下 ...

  9. python时间模块time

    时间模块 时间模块主要处理和时间相关的事件,我们可以通过模块获取不同数据类型的时间以便我们需求. 表现时间的三种方式: 在pythn中表现时间的方式主要有三种:时间戳(stamptime).元祖时间( ...

随机推荐

  1. ubuntu自带的ibus输入法问题解决方法

    ubuntu自带的ibus有点问题,输入字的时候不知道是个什么模式. 在网上搜到一个解决方法. 终端下执行: ibus-daemon -drx 然后切换到拼音输入法,就正常了. 写下作为记录.

  2. 「日常训练」Mike and Feet(Codeforces Round #305 Div. 2 D)

    题意 (Codeforces 548D) 对一个有$n$个数的数列,我们要求其连续$x(1\le x\le n)$(对于每个$x$,这样的连续group有若干个)的最小数的最大值. 分析 这是一道用了 ...

  3. win10子系统Ubuntu18.04下安装图形界面

    前提:windows 10 已经安装WSL(windows subsystem for linux),并能正确运行Bash. 要想使用Linux的图形用户界面通常有两种方法,一种是使用X-Window ...

  4. Qt Demo Http 解析网址 Openssl

    今天练习了一下Qt 解析http协议,在Demo中使用到了Openssl 一上午的时间都是编译openssl,不过还是没有成功,很遗憾,这里整理了有关这个Demo的本件 网盘连接:见下方评论吧,长传太 ...

  5. 【java并发编程实战】第七章:取消与关闭

    停止线程的几种方式 一般的逻辑停止 public class ThreadInterruptTest { public static volatile boolean cancel = true; p ...

  6. rcnn spp_net

    在http://www.cnblogs.com/jianyingzhou/p/4086578.html中 提到 rcnn开创性工作,但是计算时间太长,重复计算太大. spp_net将重复计算避免了 我 ...

  7. xml解析标签

    //获取两个标签之间的值 private static string GetStr(string message, string strStart, string strEnd) { ; ; star ...

  8. Hibernate关联映射之_一对一

    数据库模型 一般对一对一的关系而言,会存在一个主从关系.如 人 与 身份证,就是一个一对一关系, 人 是主,身份证 是从 Person PK:id name age Id_Card PK.FK:id ...

  9. LeetCode -- Tiangle

    Question: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to ...

  10. SCU3037 Painting the Balls

    Description Petya puts the \(N\) white balls in a line and now he wants to paint some of them in bla ...