コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3941 ビュー

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

アバター
破棄
関連投稿 返信 ビュー 活動
3
7月 21
6078
3
7月 25
3880
1
2月 21
9995
6
9月 19
11170
2
3月 16
7809