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)
    

      

  • 相关阅读:
    平时代码中用不到设计模式?Are you kidding me?
    关于kubernetes我们还有什么可做的?
    R语言︱文本挖掘——词云wordcloud2包
    描述性统计分析-用脚本将统计量函数批量化&分步骤逐一写出
    R语言读写中文编码方式
    R画图中英文字体完美解决方案
    Python 和 R 数据分析/挖掘工具互查
    关于ř与tableau的集成---- k均值聚类
    tableau 连接R语言
    小识Tableau
  • 原文地址:https://www.cnblogs.com/zhangjianghua/p/8528915.html
Copyright © 2011-2022 走看看