• 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类型
  • 相关阅读:
    哈希表实例
    二叉排序树算法实例
    外部中断实验
    定时器计数实验
    顺序表和有序表查找实例
    查找的普通应用实例
    矩阵键盘实验
    LED数码管显示实验
    流水灯实验
    删除注释行和空行
  • 原文地址:https://www.cnblogs.com/wangyuqi6688/p/11760800.html
Copyright © 2020-2023  润新知