473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Datetime, pytz and strange offset

Hi. I am creating a couple of small methods to help me manage time from
UTC as standard but I am getting strange results.

If I start with a datetime of 2005-12-12 14:30:00 in timezone
'America/Halifax'
and I want to turn this into a UTC representation.

from datetime import datetime
from pytz.reference import UTC
import pytz

fmt = '%Y-%m-%d %H:%M:%S %Z%z'
tz = pytz.timezone('America/Halifax')
dt = datetime(year=2005, month=12, day=11, hour=14, minute=30, second=0,
microsecond=0, tzinfo=tz)
print dt.strftime(fmt)

This is giving me a strange offset of -0414 and LMT timezone.
ie. 2005-12-12 14:30:00 LMT-0414
I am not sure where this is coming from

To get the utc equivalent using dt = dt.astimezone(UTC) I get this
strange result which is obviously also not correct:
# '2005-12-12 18:44:00 UTC+0000'

If I do datetime.now instead with the same timezone I get the correct
timezone and correct offset.

ie.
dt = datetime.now(tz=tz)
# '2005-12-12 21:37:17 AST-0400'

If I get now time from this as utc it is correct
dt = dt.astimezone(UTC)
# '2005-12-12 01:37:17 UTC+0000'

If I do a different timezone of 'America/Vancouver'
I get something appropriate for the 2:30 case

tz = pytz.timezone('America/Vancouver')
dt = datetime(year=2005, month=12, day=12, hour=14, minute=30, second=0,
microsecond=0, tzinfo=tz)
print dt.strftime(fmt)
# 2005-12-12 20:30:00 PST-0800

I am not sure why I am getting -0414 and LMT for 'America/Halifax'
timezone? Is this a bug in the pytz package? Many thanks.

Regards,
David
Dec 13 '05 #1
0 1363

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
5
by: nicolas_riesch | last post by:
Does someone know if the module pytz (http://sourceforge.net/projects/pytz/) is thread-safe ? I have not seen it explicitely stated, and just wanted to be sure, as I want to use it. That's...
1
by: Adam Monsen | last post by:
Say I have the following datetime object: >>> from datetime import datetime >>> d = datetime(2005, 8, 10, 15, 43) I happen to know this is a local time from the Netherlands, so I assume the...
1
by: James | last post by:
I need to import a bunch of data into our database for which there's a single entry each day which occurs at the same time every day in local time - so I need to convert this to UTC taking into...
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
1
by: Tino Lange | last post by:
Hi! I'm surprised about the following code, maybe you can give me a hint whether that's bug or feature? I'm just trying to convert local time to GMT and one method gives a strange result: ...
0
by: Sanjay | last post by:
Hi All, I am facing some strange problem in pytz. The timezone "Asia/Calcutta" is actually IST, which is GMT + 5:30. But while using pytz, it is being recognized as HMT (GMT + 5:53). While I...
27
by: Sanjay | last post by:
Hi All, I am using pytz.common_timezones to populate the timezone combo box of some user registration form. But as it has so many timezones (around 400), it is a bit confusing to the users. Is...
1
by: _robby | last post by:
I am looking at using pytz in a scheduling application which will be used internationally. I would like to be able to update the definition files that pytz uses monthly or bi-monthly. As far as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.