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'
Well, it looks like you are trying to get the string representation of your date object in ISO 8601 format. I don't know if you really need Z at the end, here is an alternative way to .strftime():
>>> import datetime
>>> now = datetime.datetime.now()
>>> now.replace(microsecond=0).isoformat()
'2016-04-28T17:29:53'
I am sure you can figure sth out to append Z to the string.