zoukankan      html  css  js  c++  java
  • python之时间处理time模块

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

      

  • 相关阅读:
    毕业设计进度5(2月5日)
    毕业设计进度4(2月4日)
    Intellij IDEA 安装Scala插件 + 创建Scala项目
    中国HBase技术社区第一届Meetup资料大合集
    【大会PPT+直播回顾】HBaseCon亚洲2018峰会
    Java 中的锁原理、锁优化、CAS、AQS 详解!
    Reactor 反应堆设计模式
    IO模型
    浅析Reactor设计模式
    将IDEA工程代码提交到Github
  • 原文地址:https://www.cnblogs.com/zhangjianghua/p/8528915.html
Copyright © 2011-2022 走看看