[Django]-Set default datetime format in python

2👍

I’m not sure I understand your issue, but this might help
http://docs.djangoproject.com/en/dev/ref/settings/
there is a datetime format section, this sets datetime format globally.

👤endre

5👍

strftime is a method of datetime objects – it doesn’t set a default representation, which seems to be what you suggest. For example, you might call it like this:

>>> import datetime
>>> now = datetime.datetime.now()
>>> now.strftime("%Y-%m-%d %X")
'2011-03-17 10:14:12'

If you need to do this a lot, it would be worth creating a method that wraps this conversion of a datetime to a string. The documentation for the datetime module can be found here.

Leave a comment