1. import time
  2. import datetime
  3. '''
  4. print(time.time()) #返回当前系统时间戳
  5. print(time.ctime()) #返回当前系统时间
  6. print(time.ctime(time.time()-86640)) #将时间戳转为字符串格式
  7. print(time.gmtime(time.time()-86640)) #将时间戳转换成struct_time格式
  8. print(time.localtime()) #将时间戳专程从struct_time格式,但返回的本地时间
  9. print(time.mktime(time.localtime())) #与time.localtime()功能相反,将struct_time格式转回成时间戳格式
  10. time.sleep(4) #程序睡眠4秒再执行
  11. print("******")
  12. print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))#将struct_time格式转成指定的字符串格式
  13. print(time.strptime("2018-03-06 11:51","%Y-%m-%d %H:%M"))#将字符串格式转换成struct_time格式
  14. '''
  15. '''
  16. # print(datetime.date.today())#输出格式 2018-03-06
  17. # print(datetime.date.fromtimestamp(time.time()-866400))#2018-02-24将时间戳转为日期格式
  18. # current_time = datetime.datetime.now()#
  19. # print(current_time)#输出2018-03-06 14:31:38.781600
  20. # print(current_time.timetuple())#返回struct_time格式
  21. # print(current_time.replace(2017,3,6))#输出2017-03-06 14:53:06.932600,返回当前时间,但指定的值将被替换
  22. # str_to_date = datetime.datetime.strptime("2018/3/6 14:56","%Y/%m/%d %H:%M")#将字符串转换为日期格式
  23. # print(str_to_date)
  24. '''
  25. # new_date = datetime.datetime.now() + datetime.timedelta(days=10)#比现在增加10天
  26. # new_date = datetime.datetime.now() + datetime.timedelta(days=-10)#比现在减少10天
  27. # new_date = datetime.datetime.now() + datetime.timedelta(hours=-10)#比现在减少10小时
  28. # new_date = datetime.datetime.now() + datetime.timedelta(seconds=120)#比现在增加120秒
  29. # new_date = datetime.datetime.now() + datetime.timedelta(minutes=30)#比现在增加30分钟
  30. # print(new_date)

  

python之时间处理time模块的更多相关文章

  1. python的时间处理-time模块

    time模块 时间的表示方法有三种: 时间戳:表示的是从1970年1月1日0点至今的秒数 格式化字符串表示:这种表示更习惯我们通常的读法,如2018-04-24 00:00:00 格式化元祖表示:是一 ...

  2. Python之时间:datetime模块

    datetime在time基础之上封装了一些方法.但是time是经常使用的,datetime中的功能,time都能实现 一.datetime的三个模块 datetime.date datetime.t ...

  3. Python之时间:time模块

    import time   对于时间,使用最频繁的模块 1.获取当前时间 (1)时间戳 time.time() 时间戳:从1970年1月1日0点开始到现在按秒计算的偏移量 (2)时间元组 time.l ...

  4. Python之时间和日期模块

    1.import time 先要导入时间模块 1)time.time()得到当前的时间,返回的是时间戳,表示自1970年1月1日起到程序运行时的秒数 import time print(time.ti ...

  5. Python之时间:calender模块(日历)

    import calendar 1.星期 (1)calendar.day_name 星期的全称 print calendar.day_name for i in calendar.day_name: ...

  6. Python日期时间Date/Time

    Python程序可以处理多种方式的日期和时间.日期格式之间的转换是一种常见计算机的杂活. Python的时间和日历模块,能帮助处理日期和时间. Tick是什么? 为时间间隔,以秒为单位的浮点数.从“新 ...

  7. python 统计时间,写日志

    python 统计时间使用time模块,写日志使用logging模块,这两个都是标准模板. 测试socket使用socket模块 # 统计时间 ---------------------- impor ...

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

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

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

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

随机推荐

  1. TCP的连接和释放过程

    TCP的连接和释放过程 1.三次握手的过程 1)主机A向主机B发送TCP连接请求数据包,其中包含主机A的初始序列号seq(A)=x.(其中报文中同步标志位SYN=1,ACK=0,表示这是一个TCP连接 ...

  2. 给类型为text的input设置value值却无法修改

    给类型为text的input设置value值后就无法修改了 我的页面显示为如下但是退格却无法改变他的值 原来是缺少onChange事件,没法监听value的改变 所以需要添加 onChange={th ...

  3. 原生js添加类名,删除类名

    1.添加类名: document.getElementById("myDiv").classList.add('mystyle'); 2.删除类名: document.getEle ...

  4. web安全防御之RASP技术

    作者:      我是小三 博客:      http://www.cnblogs.com/2014asm/ 由于时间和水平有限,本文会存在诸多不足,希望得到您的及时反馈与指正,多谢! 0x00:we ...

  5. Jquery里面的$(this)和this, 有什么区别

    当你用的是jquery时,就用$(this),如果是JS,就用this $(this).html( $(this).html() + " BAM! "); 这个里的html()是J ...

  6. codeforces 600D Area of Two Circles' Intersection

    分相离,内含,想交三种情况讨论一下. 主要是精度和数据范围的问题,首先数据用long double,能用整型判断就不要用浮点型. 题目中所给的坐标,半径是整型的,出现卡浮点判断的情况还是比较少的. 最 ...

  7. SqlServer 学习笔记

    随机函数 select rand() declare @age int set @age = rand()*100 select @age 数据类型转换 declare @birthday datat ...

  8. python_47_Python2中字符编码与转码

    #python3默认是Unicode,Unicode是万国码,不管中文字符还是英文,所有的每个字符都占2个字节空间,16位 #python2默认是ascii码 #ascii码不能存中文,一个英文只能占 ...

  9. python_39_变量补充

    #使用eval()函数计算字符串中的有效表达式,并返回结果 a='1+3' print(eval(a)) b='''{ '闵行': { '人民广场': { '炸鸡店': {}, }, } ''' pr ...

  10. 通过cmd查看环境变量名对应的环境变量值

    在VS环境中通常要添加路径,不过基本都是按照往上提供的方法添加变量名形如:$(VC_IncludePath),但是如何通过cmd命令找到真正的路径呢 未完待续……