New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datetime buggy #67183
Comments
val=datetime.datetime.strptime("2015-02-01",'%Y-%m-%d').date()
zon=pytz.timezone('US/Pacific')
dt=datetime.datetime(val.year,val.month,val.day, tzinfo=zon)
print dt,zon output: output should be |
Datetimes in local timezones should be created using localize(): >>> zon.localize(datetime.datetime(2015, 2, 1)).isoformat()
'2015-02-01T00:00:00-08:00' See the two supported methods of creating local datetimes at: http://pytz.sourceforge.net |
i dont need local timezone |
zon=pytz.timezone('America/New_York')
dt=datetime.datetime(2014,02,01, tzinfo=zon)
print dt,zon => 2015-02-01 00:00:00-04:56 America/New_York zon=pytz.timezone('Asia/Kolkata')
dt=datetime.datetime(2014,02,01, tzinfo=zon)
print dt,zon =>2015-02-01 00:00:00+05:53 Asia/Kolkata all most for all timezones it is giving erroronous outputs |
pytz is not a part of the python standard library, it is a 3rd party product. Please reread Simeon's message (he's talking about any timezone), and if you have further questions ask on whatever support forum pytz has, or on the python-list mailing list. |
santhosh, I would be interested to know how this gets resolved. I find it strange that zon gets fractional UTC offset: >>> zon
<DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD> If you ask on a pytz-related forum, please post a link here. Some other cases: >>> pytz.timezone('US/Eastern')
<DstTzInfo 'US/Eastern' LMT-1 day, 19:04:00 STD>
>>> pytz.timezone('US/Central')
<DstTzInfo 'US/Central' LMT-1 day, 18:09:00 STD>
>>> pytz.timezone('Asia/Kolkata')
<DstTzInfo 'Asia/Kolkata' LMT+5:53:00 STD> but >>> pytz.timezone('Europe/Paris')
<DstTzInfo 'Europe/Paris' LMT+0:09:00 STD> |
It looks like pytz documentation [1] specifically warns about this kind of usage: """ [1] http://pytz.sourceforge.net/#localized-times-and-date-arithmetic |
Thanks simeon.visser, Hey belopolsky, Bad Code: In Linux, good code works perfectly Both code are working perfectly in Mac |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: