Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
3996 Visninger

Hi,

my goal is to display a datetime in the format hours:minutes in a tree view.

I first tried to format my datetime directly in the XML but without success.

Then, I decided to create a new field in my model :

heure_debut = fields.Char(string="Test"compute="_compute_jour")


I defined its value in the following function :

@api.depends('start_date')
    def _compute_jour(self):
        for meeting in self:
            if meeting.start:
                meeting.heure_debut = meeting.start.time().strftime("%H:%M")


The problem I have is that the string has a difference of one hour with the datetime

For example I have this :

Datetime                                    Test

22/02/2021 01:00:00                  00:00

22/02/2021 04:00:00                 03:00   


I think it comes from the timezone but I don't understand how I can include the timezone in the code to obtain the correct string. I could just add an hour to the datetime but I think I will have problems with the time change.


Thank you

Avatar
Kassér
Related Posts Besvarelser Visninger Aktivitet
3
jul. 21
6096
3
jul. 25
3911
1
feb. 21
10032
6
sep. 19
11184
2
mar. 16
7827