Date Time split in python

前端 未结 5 1651
再見小時候
再見小時候 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:41

    Use datetime.strptime(your_string, format)

    To contsruct the format string, consult the documentation: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior

    From there, you can easily get the year, month, etc. (also in the documentation)

提交回复
热议问题