zoukankan      html  css  js  c++  java
  • python时间处理

    ## time模块

    print("time stamp:", time.time())         # 时间戳:1479193181.829338
     
    print("local time:", time.localtime())    # struct_time类型的本地时间
    time.struct_time(tm_year=2016, tm_mon=11, tm_mday=15, tm_hour=14, tm_min=59, tm_sec=41, tm_wday=1, tm_yday=320, tm_isdst=0)
     
    print("utc time:", time.gmtime())         # struct_time类型的utc时间
    time.struct_time(tm_year=2016, tm_mon=11, tm_mday=15, tm_hour=6, tm_min=59, tm_sec=41, tm_wday=1, tm_yday=320, tm_isdst=0)
    time_stamp = time.time()               # 时间戳
    local_time = time.localtime(time_stamp)# 时间戳转struct_time类型的本地时间
    utc_time = time.gmtime(time_stamp)     # 时间戳转struct_time类型的utc时间
     
    time_stamp_1 = time.mktime(local_time) # struct_time类型的本地时间转时间戳
    time_stamp_2 = calendar.timegm(utc_time)# struct_time类型的utc时间转时间戳
    print(time.ctime(time_stamp))       # 时间戳转字符串(本地时间字符串)
     
    print(time.asctime(local_time))     # struct_time类型的本地时间转字符串
    print(time.asctime(utc_time))       # struct_time类型的utc时间转字符串
     
    # struct_time类型的本地时间转字符串:自定义格式
    print(time.strftime("%Y-%m-%d, %H:%M:%S, %w", local_time))
    # struct_time类型的utc时间转字符串:自定义格式
    print(time.strftime("%Y-%m-%d, %H:%M:%S, %w", utc_time))
     
    struct_time = time.strptime("2016-11-15, 15:32:12, 2", "%Y-%m-%d, %H:%M:%S, %w")       # 字符串转struct_time类型
  • 相关阅读:
    Java并发学习笔记
    OSI七层网络模型
    网络寻址过程
    ThinkPhp之Rce分析
    Java cc6
    Java cc1
    Yso中的URLDNS分析学习
    JWT攻防
    权限维持之创建本地账号(T1136.001)
    redis配置修改后不生效的原因
  • 原文地址:https://www.cnblogs.com/wangyuqi6688/p/11760800.html
Copyright © 2011-2022 走看看