Parse date string and change format

后端 未结 9 664
孤街浪徒
孤街浪徒 2020-11-22 00:58

I have a date string with the format \'Mon Feb 15 2010\'. I want to change the format to \'15/02/2010\'. How can I do this?

相关标签:
9条回答
  • 2020-11-22 01:59
    >>> from_date="Mon Feb 15 2010"
    >>> import time                
    >>> conv=time.strptime(from_date,"%a %b %d %Y")
    >>> time.strftime("%d/%m/%Y",conv)
    '15/02/2010'
    
    0 讨论(0)
  • 2020-11-22 02:00

    @codeling and @user1767754 : The following two lines will work. I saw no one posted the complete solution for the example problem that was asked. Hopefully this is enough explanation.

    import datetime
    
    x = datetime.datetime.strptime("Mon Feb 15 2010", "%a %b %d %Y").strftime("%d/%m/%Y")
    print(x)
    

    Output:

    15/02/2010
    
    0 讨论(0)
  • 2020-11-22 02:00

    use datetime library http://docs.python.org/library/datetime.html look up 9.1.7. especiall strptime() strftime() Behavior¶ examples http://pleac.sourceforge.net/pleac_python/datesandtimes.html

    0 讨论(0)
提交回复
热议问题