开发者

set default datetime format in python

How to set default datetime format in python because 开发者_开发百科i have multiple tuples to send via template on client side. This is not good approach to set each object's value to specified format. I want to set a datetime format on server side and these converted values will be shown to client. I tried

datetime.strftime("%Y-%m-%d %X")

but it is giving error.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜