Date Time split in python

前端 未结 5 1582
再見小時候
再見小時候 2021-02-07 22:58

I have to split a date time which I get from a software in the below format to separate variables (year,month,day,hour, min,sec)

19 Nov 2015  18:45:00.000
         


        
5条回答
  •  遥遥无期
    2021-02-07 23:31

    First pip install python-dateutil then do:

    >>> from dateutil.parser import parse
    >>> dt = parse('19 Nov 2015  18:45:00.000')
    >>> dt.year
    2015
    >>> dt.month
    11
    >>> dt.day
    19
    >>> dt.hour
    18
    >>> dt.minute
    45
    >>> dt.second
    0
    

提交回复
热议问题