Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
3313 Lượt xem

Hi,I want to change date format for some date field.Not for all date field.I know I can change for all using Settings --> Translations --> Languages.But I want to change some particular field only.I try to use this but not work. 

My code example:

 




Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello, you can try below process :

Translations --> Language --> Edit

Replace time format : %H:%M:%S to %I:%M:%S %p

import following:

from odoo.tools import float_is_zero, float_compare, DEFAULT_SERVER_DATETIME_FORMAT

define in your function in place of time format DEFAULT_SERVER_DATETIME_FORMAT i hope it helps you.


For Reports and XML(QWeb) you can do it this way:

<span t-esc="datetime.datetime.strptime(object.date, '%Y-%m-%d %H:%M:%S').strftime('%d/%m/%Y %I:%M:%S %p')"/>

Hope it helps

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 1 25
6479
1
thg 8 24
4225
0
thg 9 21
3862
0
thg 3 15
5702
3
thg 5 25
7386