How to get formatted date time in python
Question: I want my Linux Filename like this

    
    
    May-01-0340AM-2011.tar
    

How can i get the date variable formatted like above in Python

IN bash i write

    
    
    date1=$(date +"%b-%d-%I%M%p-%G")
    


Answer: You can use the same formatting string in `strftime` on a [datetime
object](http://docs.python.org/library/datetime.html#datetime-datetime):

    
    
    >>> import datetime
    >>> datetime.datetime.now().strftime('%b-%d-%I%M%p-%G')
    'May-16-0245PM-2011'
    

Incidentally, I'd just like to put a word in for the joy of [ISO-8601 date
formatting](http://www.cl.cam.ac.uk/~mgk25/iso-time.html) :)

