How can I get a date in the foll. format in python:
2016-04-26T19:50:48Z
I am doing this:
import datetime
now = datetime.now()
now.strftime("%Y %m %d %H:%M")
Well, first, you're not getting now() properly. That's in datetime.datetime, not in the top level datetime. Second, it doesn't seem like you've attempted to get the format string you wanted - it doesn't even have the dashes you specify.
>>> import datetime
>>> now = datetime.now()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'now'
>>> now = datetime.datetime.now()
>>> now.strftime("%Y %m %d %H:%M")
'2016 04 28 17:20'
>>> now.strftime("%Y-%m-%dT%H:%M:%SZ")
'2016-04-28T17:20:09Z'
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