4

Is there any way to display time(datetime) in UTC by default in odoo?

By default it is displaying time according to System's timezone.

Thanks

Anonymous
  • 307
  • 4
  • 10

2 Answers2

2

I hope this will help your problem.

import pytz

timezone = pytz.timezone(self._context.get('tz') or 'UTC')
self.date_depart_filtre = timezone.localize(datetime.strptime(self.date_depart,'%Y-%m-%d %H:%M:%S')).astimezone(pytz.UTC)

In odoo this type Of stuff also do :

@api.one
@api.depends('date_depart')
def _get_filter_date(self):
    if not (self.date_depart):
        self.date_depart_filtre = self.date_depart
        return
    my_tz = pytz.timezone(self._context.get('tz') or 'UTC')
    #my_tz = pytz.timezone('Europe/Paris')
    utc_tz = tz.tzutc()
    my_dt = datetime.strptime(self.date_depart,'%Y-%m-%d %H:%M:%S')
    utc_dt = my_dt.replace(tzinfo=utc_tz)
    self.date_depart_filtre = utc_dt.astimezone(my_tz)
    return
Jainik Patel
  • 2,284
  • 1
  • 15
  • 35
0

You can set the timezone as UTC from Preferences menu, defined under the Logged user name, at the Top right of your Odoo screen.

Priyesh Solanki
  • 707
  • 4
  • 6