zoukankan      html  css  js  c++  java
  • python 根据时间戳获取秒🐱

    print("当前时间: ",time.strftime('%Y.%m.%d %H:%M:%S ',time.localtime(time.time())))
    
    
    import time
    import datetime
    t = time.time()
    print (t)                       #原始时间数据
    print (int(t))                  #秒级时间戳
    print (int(round(t * 1000)))    #毫秒级时间戳
    nowTime = lambda:int(round(t * 1000))
    print (nowTime());              #毫秒级时间戳,基于lambda
    print (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))   #日期格式化
    #输出
    1499825149.26
    1499825149
    1499825149257
    1499825149257
    2017-07-12 10:05:49
    
    
    #将日期转为秒级时间戳
    dt = '2018-01-01 10:40:30'
    ts = int(time.mktime(time.strptime(dt, "%Y-%m-%d %H:%M:%S")))
    print (ts)
    #输出
    1514774430
    
    
    #将秒级时间戳转为日期
    ts = 1515774430
    dt = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
    print(dt)
    #输出
    2018-01-13 00:27:10
    
    参考:
    https://www.cnblogs.com/fangbei/p/python-time.html

  • 相关阅读:
    Python合集之Python循环语句(二)
    io流2
    io流
    集合工具类
    泛型
    Map
    VSCode_Extensions
    C++ in VSCode
    C# 私有字段前缀 _ 的设置(VS2019, .editorconfig)
    dotnet 跨平台编译发布
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11100333.html
Copyright © 2011-2022 走看看