Tuesday, 15 May 2012

PHP to Python conversion to get timezone offset -



PHP to Python conversion to get timezone offset -

i new python , same thing below in python instead of php.

$timestamp = 1414231200; $timezone = 'australia/nsw'; $offset = timezone_offset_get(timezone_open($timezone), new datetime()); //39600 (11 hours) $adjust = $timestamp + $offset; $new = new datetime('@'.$adjust); print_r($new->format('y-m-d\th:i:s'));

result: 2014-10-25t21:00:00

i using gae (google app engine) , looks can't import pytz. there other solutions?

i have tried:

from datetime import datetime pytz import timezone import pytz timestamp = 1415700000; timezone = timezone('australia/nsw') format = '%y-%m-%d\t%h:%m:%s' #not sure how offset new = timezone.localize(datetime.fromtimestamp(timestamp)) new.strftime(format) print(new)

but error: importerror: no module named pytz

you might able utilize , accomplish this: https://code.google.com/p/gae-pytz/ think might able utilize pytz, you'll have manually install it: how add together pytz google app engine application?

php python google-app-engine timezone timezoneoffset

No comments:

Post a Comment