Python - Time data not match format

前端 未结 4 952
深忆病人
深忆病人 2021-01-27 00:42

I have string time in the following format

2016-12-10T13:54:15.294

I am using the following method to format the time:

time.strptime(

4条回答
  •  爱一瞬间的悲伤
    2021-01-27 01:03

    You need to first parse the string as its formatted, then print it out the way you want.

    >>> import datetime
    >>> ts = "2016-12-10T13:54:15.294"
    >>> parsed = datetime.datetime.strptime(ts, '%Y-%m-%dT%H:%M:%S.%f')
    >>> parsed
    datetime.datetime(2016, 12, 10, 13, 54, 15, 294000)
    >>> parsed.strftime('%b %d %H:%M:%S %Y')
    'Dec 10 13:54:15 2016'
    

提交回复
热议问题