zoukankan      html  css  js  c++  java
  • 常用模块之time模块

    import time
    #获取当前的时间戳  浮点型
    floatStamp = time.time()
    print(floatStamp)
    #获取当前的时间戳  整型
    intStamp = int(time.time())
    print(intStamp)
    #从返回的浮点数的时间戳转成时间元组 
    localtime = time.localtime()
    print(localtime) #time.struct_time(tm_year=2018, tm_mon=11, tm_mday=20, tm_hour=23, tm_min=11, tm_sec=57, tm_wday=1, tm_yday=324, tm_isdst=0)
    #将时间字符串解析成时间元组
    tupleTime = time.strptime('2018-11-20 23:40:50','%Y-%m-%d %H:%M:%S')
    print(tupleTime) # time.struct_time(tm_year=2018, tm_mon=11, tm_mday=20, tm_hour=23, tm_min=40, tm_sec=50, tm_wday=1, tm_yday=324, tm_isdst=-1)
    #将时间戳转成格式化时间
    timeFormat1 = time.asctime(time.localtime(time.time()))
    print(timeFormat1) # Thu Apr  7 10:05:21 2016
    timeFormat2 = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    print(timeFormat2) # 2018-11-20 23:23:18
    #将格式化时间转成时间戳
    formatTime = '2018-11-20 23:23:18'
    tf = int(time.mktime(time.strptime(formatTime,'%Y-%m-%d %H:%M:%S')))
    print(tf) # 1542727398
    #时间元组转成时间戳【浮点时间戳】 (tm_year,tm_month,tm_day,tm_hour,tm_min,tm_sec,tm_wday,tm_isdst)
    t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)
    floatStamp = time.mktime(t) # 1234861418.0
    print(floatStamp)
    #推迟线程的运行,单位是秒
    time.sleep(10) #休眠10s
  • 相关阅读:
    Java简单获取当前时间
    基EmguCv/OpenCv的零件的缺陷检测
    cURL实现模拟登陆+抓取数据
    Learnjava--色子点数概率(转)
    java读写txt文件
    java jdk1.8连接sql server数据库
    简单随机选人网站设计
    封装cURL工具类
    在Linux下安装PHP的curl扩展
    Jsp四种变量作用范围
  • 原文地址:https://www.cnblogs.com/wuxiaoshi/p/9992640.html
Copyright © 2011-2022 走看看