In python, how would I generate a timestamp to this specific format?
2010-03-20T10:33:22-07
I've searched high and low, but I couldn't find the correct term that describes generating this specific format.
Use strftime() function of a datetime class The format codes are standard directives for mentioning in which format you want to represent datetime. For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.
To get the current time in particular, you can use the strftime() method and pass into it the string ”%H:%M:%S” representing hours, minutes, and seconds.
See the following example:
import datetime now = datetime.datetime.now() now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000))
This could result in the following: '2017-09-20T11:52:32-98'
You can use datetime with strftime. Exemple:
import datetime date = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f") print(date)
Will print:
2017-09-20T12:59:43.888955
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With