How do I generate a python timestamp to a particular format?


In python, how would I generate a timestamp to this specific format?


I’ve searched high and low, but I couldn’t find the correct term that describes generating this specific format.

Asked By: user3768071



You can use datetime with strftime. Exemple:

import datetime

date ="%Y-%m-%dT%H:%M:%S.%f")


Will print:

Answered By: Lame Fanello

See the following example:

import datetime 
now =
now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000))

This could result in the following:

Answered By: Henk Dekker
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.