Python获取当前年月日

发布时间:2019-09-07 07:55:36编辑:auto阅读(2084)

    import datetime
    datetime.datetime.now().year
    datetime.datetime.now().month
    datetime.datetime.now().day
    
    [root@skyeye ~]# python 
    Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import datetime
    >>> datetime.datetime.now().year
    2018
    >>> datetime.datetime.now().month
    11
    >>> datetime.datetime.now().day
    14

     

关键字