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'>
  • 相关阅读:
    C# COM DLL 给vba调用
    c# autocad 通过进程向cad发送command
    AutoCAD Excel script
    c# 自动生成 autocad cuix
    AutoCAD 批处理打印文件
    c# 一套代码多个配置生成多个程序
    获取本机的com对象的progid和类型库的位置
    mybatis SqlMapConfig.xml配置
    GDAL 处理shape自相交图形
    PostGIS 常用函数
  • 原文地址:https://www.cnblogs.com/huafan/p/9867465.html
Copyright © 2011-2022 走看看