zoukankan      html  css  js  c++  java
  • Python3, Python2 获取当前时间

    # Python2
    import time
    
    def get_current_time():
        current_time = time.localtime(time.time())
        current_time = time.strftime('%Y-%m-%d %H:%M:%S', current_time)
        return current_time
    
    print(get_current_time())      # 2021-01-18 17:18:10
    
    # Python3
    from datetime import datetime
    
    current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    print(current_time)      # 2021-01-18 17:18:10
    

    python中时间日期格式化符号:

    • %y 两位数的年份表示(00-99)
    • %Y 四位数的年份表示(000-9999)
    • %m 月份(01-12)
    • %d 月内中的一天(0-31)
    • %H 24小时制小时数(0-23)
    • %I 12小时制小时数(01-12)
    • %M 分钟数(00=59)
    • %S 秒(00-59)
    • %a 本地简化星期名称
    • %A 本地完整星期名称
    • %b 本地简化的月份名称
    • %B 本地完整的月份名称
    • %c 本地相应的日期表示和时间表示
    • %j 年内的一天(001-366)
    • %p 本地A.M.或P.M.的等价符
    • %U 一年中的星期数(00-53)星期天为星期的开始
    • %w 星期(0-6),星期天为星期的开始
    • %W 一年中的星期数(00-53)星期一为星期的开始
    • %x 本地相应的日期表示
    • %X 本地相应的时间表示
    • %Z 当前时区的名称
    • %% %号本身
  • 相关阅读:
    Colidity-- NumberOfDiscIntersections
    Colidity--Triangle
    Colidity--CountDiv
    Colidity--MinAvgTwoSlice
    Colidity--GenomicRangeQuery
    Colidity--PassingCars
    操作系统--内存管理方式
    蓝桥杯练习系统—算法训练 P1102
    蓝桥杯练习系统—基础练习 完美的代价
    2n皇后问题
  • 原文地址:https://www.cnblogs.com/MasonHu/p/14293635.html
Copyright © 2011-2022 走看看