Question

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 :)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top