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

Why is it that hr_timesheet_invoice_create.py needs

from dateutil import tz
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
arrive = arrive.replace(tzinfo=from_zone)
arrive_central = arrive.astimezone(to_zone)

to display the correct time information?

Ảnh đại diện
Huỷ bỏ
Tác giả

And it seems .mako files are even further away from displaying the correct time information. This code doesn't work in mako files; I still get UTC.

Tác giả Câu trả lời hay nhất

The following code works fine in my makos.

import pytz
# ...
time_local = 'America/Chicago'
time_fmt = "%Y-%m-%d %H:%M"
arrive_dt = datetime.utcnow()
testDt=pytz.utc.localize(arrive_dt)
TestDt = testDt.astimezone(pytz.timezone(time_local))
Arrive=TestDt.strftime(time_fmt)

Good luck!

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 24
8528
0
thg 3 15
5673
2
thg 12 23
16794
1
thg 3 15
3232
1
thg 9 20
5936