zoukankan      html  css  js  c++  java
  • 参数里时间格式的转换

    https://blog.csdn.net/holdlg/article/details/62436537

    time.time()  得到浮点型的时间戳

    time.localtime() 都得到 struct_time

    time.strftime() 可以这么理解 “string format time” 格式化,格式成年月日时分秒

    time.strptime() 可以理解为 “string parser time” 反格式化,反格式成本地格式

    time.mktime() 转换成时间戳

     

    时间戳转换日期
    time.time() => localtime=> strftime 

    import time

    # 时间戳
    now = time.time()
    // 1489657751.1138341

    int(now)
    // 1489657751

    // 时间
    tl = time.localtime(now)
    // time.struct_time(tm_year=2017, tm_mon=3, tm_mday=16, tm_hour=18, tm_min=35, tm_sec=10, tm_wday=3, tm_yday=75, tm_isdst=0)


    # 格式化时间
    format_time = time.strftime("%Y-%m-%d %H:%M:%S", tl)
    // 2017-03-16 18:22:06

    时间转换时间戳
    strptime=> mktime

    import time

    # 格式化时间
    format_time = '2017-03-16 18:22:06'

    # 时间
    ts = time.strptime(format_time, "%Y-%m-%d %H:%M:%S")
    // time.struct_time(tm_year=2017, tm_mon=3, tm_mday=16, tm_hour=18, tm_min=35, tm_sec=10, tm_wday=3, tm_yday=75, tm_isdst=0)

    # 格式化时间转时间戳
    time.mktime(ts)
    // 1489660028.0

    毫秒时间戳(13位)/1000=秒时间戳(10位)

     

  • 相关阅读:
    IndexDB
    实现es6中的set和map
    视口viewport
    nginx入门
    http协议
    图像格式
    promise
    js中this指向
    CSS 7阶层叠水平
    C# 一个方法如何返回多个值
  • 原文地址:https://www.cnblogs.com/yzwdcjs/p/14489711.html
Copyright © 2011-2022 走看看