Python - Time data not match format

前端 未结 4 951
深忆病人
深忆病人 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:13

    Your format string is not correct.

    You can check format string just using strftime method of date object. For example:

    d = datetime.datetime.now()
    print(d.strftime('%Y-%d-%mT%H:%M:%S'))
    

    Output:

    Dec 16 11:02:46 2016
    

    But you have string in following format 2016-12-10T13:54:15.294, so you just need to change format string:

    print(time.strptime(ts, '%Y-%d-%mT%H:%M:%S.%f'))
    

    output:

    time.struct_time(tm_year=2016, tm_mon=10, tm_mday=12, tm_hour=13, tm_min=54, tm_sec=15, tm_wday=2, tm_yday=286, tm_isdst=-1)
    

提交回复
热议问题