Reputation: 11052
A Event class in models.py
class Event(models.Model):
timestamp = models.DateTimeField()
message = models.TextField()
def __unicode__(self):
return "'%s' at %s" % (self.message, self.timestamp)
def api_detail(self):
return {
'timestamp': str(self.timestamp),
'description': self.message,
There is UTC time saved in database. but i want to fetch it in localize time. For example timestamp will return : Feb. 14, 2012 , 7 p.m.. This time is in UTC i want to change it into a local time.
Please help me in this matter :)
Upvotes: 1
Views: 1362
Reputation: 1500525
Local time in which time zone? The pytz documentation suggests that once you've decided which zone to use, it's as simple as:
local_time = zone.localize(timestamp)
Note that converting from UTC to local time is unambiguous, whereas the reverse is not.
Upvotes: 3