Convert time to string with milliseconds
Question: Python datetime.now() gives me current time including milliseconds like this:

    
    
    2014-08-22 19:23:40.630000
    

How do I convert the above datetime object to a string that includes the
milliseconds?

I looked into `time.strftime()` but it does not provide an option for
milliseconds.

Ideas?

Thanks.


Answer: Use datetime.strftime. In Python 3.4.1:

    
    
    from datetime import datetime
    mytime= datetime.now()
    s= mytime.strftime("%Y-%b-%d %H:%M:%S.%f")
    print(s)
    '2014-Aug-23 08:51:32.911271'
    

