zoukankan      html  css  js  c++  java
  • 常用日期方式

    from datetime import datetime
    import time
    
    #python里使用time模块来获取当前的时间
    
    print (time.strftime("%H:%M:%S"))    ##24小时格式 :21:45:33
    print (time.strftime("%H-%M-%S"))    ##24小时格式 :21-50-01
    
    print (time.strftime("%I:%M:%S"))  ## 12小时格式 :09:45:33
    print (time.strftime("%I-%M-%S"))  ## 12小时格式 :09-49-33
    #--------------------------------------------------------------------------
    
    ## dd/mm/yyyy格式
    
    print (time.strftime("%d/%m/%Y"))   #:27/02/2020
    print (time.strftime("%Y/%m/%d"))   #:2020/02/27
    print (time.strftime("%Y-%m-%d"))   #:2020-02-27
    
    #--------------------------------------------------------------------------
    
    print (time.strftime("%Y-%m-%d-%I-%M-%S"))   #:2020-02-27-09-51-02
    
    print(type(time.strftime("%Y-%m-%d-%I-%M-%S")))  #:<class 'str'>
    
    #--------------------------------------------------------------------------
    print(datetime.now())      #:2020-02-27 21:51:36.752944
    
    print(time.asctime())      #Thu Feb 27 21:51:36 2020
    
    #--------------------------------------------------------------------------
    
    cur=datetime.now()
    
    print(cur.year)  #:2020
    
    print(cur.month)  #:2
    
    print(cur.day)  #:27
    
    print(cur.hour)  #:21
    
    print(cur.minute)  #:56
    
    print(cur.second)  #:5
    
    #--------------------------------------------------------------------------

    执行结果:

    21:57:05
    21-57-05
    09:57:05
    09-57-05
    27/02/2020
    2020/02/27
    2020-02-27
    2020-02-27-09-57-05
    <class 'str'>
    2020-02-27 21:57:05.603468
    Thu Feb 27 21:57:05 2020
    2020
    2
    27
    21
    57
    5

  • 相关阅读:
    NDK中使用pthread多线程中自己写的一个BUG
    Android Native crash日志分析
    Android细笔记--DataStorage
    求二叉树第n层节点数
    对YUV数据进行裁剪
    Android XML中引用自定义内部类view的四个why
    Android细笔记--ContentProvider
    Android Log Tag含义
    189-RotaeArray
    二分查找法
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12374731.html
Copyright © 2011-2022 走看看