zoukankan      html  css  js  c++  java
  • 008 python语法_类 time

    '''
    时间:2018/10/28
    目录: 
      一: 概述
            1 help查看
            2 文件查看
            3 类型查看
      二: 使用
            1 获取时间戳
            2 获取当前时间
            3 获取日历
            4 获取日期
            5 获取日期 - 精确毫秒
    '''

    一: 概述
      1 help查看

    # coding:utf-8
    import time
    
    help(time)
    D:ProgramToolsPythonpython.exe "D:/ProgramTools/PyCharm 5.0.4/PycharmProject/StudyJson/StudyJson/Study001.py"
    Help on built-in module time:
    
    NAME
        time - This module provides various functions to manipulate time values.
    
    DESCRIPTION
        There are two standard representations of time.  One is the number
        of seconds since the Epoch, in UTC (a.k.a. GMT).  It may be an integer
        or a floating point number (to represent fractions of seconds).
        The Epoch is system-defined; on Unix, it is generally January 1st, 1970.
        The actual value can be retrieved by calling gmtime(0).
        

      2 文件查看

    # encoding: utf-8
    # module time
    # from (built-in)
    # by generator 1.138
    """
    This module provides various functions to manipulate time values.
    
    There are two standard representations of time.  One is the number
    of seconds since the Epoch, in UTC (a.k.a. GMT).  It may be an integer
    or a floating point number (to represent fractions of seconds).
    The Epoch is system-defined; on Unix, it is generally January 1st, 1970.
    The actual value can be retrieved by calling gmtime(0).

      3 类型查看

    # coding:utf-8
    import time
    
    print(type(time))
    <class 'module'>
    
    Process finished with exit code 0

    二: 使用
      1 获取时间戳

    # coding:utf-8
    import time
    
    ticks = time.time()        # 获取当前时间戳
    print(ticks)
    print(type(ticks))
    1540734821.25581
    <class 'float'>

      2 获取当前时间

    # coding:utf-8
    import time
    
    localtime = time.localtime(time.time())        # 获取当前时间戳
    print(localtime)
    print(type(localtime))
    time.struct_time(tm_year=2018, tm_mon=10, tm_mday=28, tm_hour=21, tm_min=54, tm_sec=20, tm_wday=6, tm_yday=301, tm_isdst=0)
    <class 'time.struct_time'>

      3 获取日历

    # coding:utf-8
    import calendar
    
    cal = calendar.month(2018, 10)  # 获取某月日历
    print(cal)
    print(type(cal))
        October 2018
    Mo Tu We Th Fr Sa Su
     1  2  3  4  5  6  7
     8  9 10 11 12 13 14
    15 16 17 18 19 20 21
    22 23 24 25 26 27 28
    29 30 31
    
    <class 'str'>

      4 获取日期

    # coding:utf-8
    import time
    
    strTime = time.strftime("%Y/%m/%d %H:%M:%S")    # 格式化日期
    print(strTime)
    print(type(strTime))
    2018/10/28 21:58:55
    <class 'str'>

      5 获取日期 - 精确毫秒

    # coding:utf-8
    import datetime
    
    strTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S %f')    # 获取日期 - 精确毫秒
    print(strTime)
    print(type(strTime))
    2018-10-28 22:01:35 751949
    <class 'str'>
  • 相关阅读:
    龙东平:持续提升个人认知的三大底层逻辑
    【科创人独家】美信拓扑创始人一乐:如何登山不是最重要的问题,山峰才是
    【科创人独家】搜狐快站金庸:有情有义,90后技术创业者的问剑之路
    【科创人独家】军哥手记程军:我的2020,先打个60分吧
    【科创人独家】云风:从创业到招安,自由的游戏玩家+务实的程序员
    C语言--->指针
    位运算(一)
    平方根倒数快速算法
    IntelliJ IDEA 配置《算法》(第四版)
    深度学习(一):Python神经网络——手写数字识别
  • 原文地址:https://www.cnblogs.com/huafan/p/9867465.html
Copyright © 2011-2022 走看看