Python - get UTC offset by seconds

Based on this code, how do I get the UTC offset of a given date by seconds. get UTC offset from time zone name in python

Currently, I have this code:

Python 2.7.3 (default, Jul  3 2012, 19:58:39) 
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytz
>>> import datetime
>>> offset = datetime.datetime.now(pytz.timezone('US/Pacific')).strftime('%z')
>>> offset
'-0700'
>>> int(offset)*3600
-2520000
>>> int(offset)*360 
-252000
>>> 

For example, US/Pacific sometimes is -800 hours (probably military time :D) but I need it to be in seconds, ex: -25200.

Shall I just multiply it by 360? Doesn't sound right but who knows.

TIA

Answers


>>> import datetime, pytz
>>> melbourne = pytz.timezone("Australia/Melbourne")
>>> melbourne.utcoffset(datetime.datetime.now())
datetime.timedelta(0, 36000)

>>> pacific = pytz.timezone("US/Pacific")
>>> pacific.utcoffset(datetime.datetime.now())
datetime.timedelta(-1, 61200)
>>> -1*86400+61200
-25200
>>> pacific.utcoffset(datetime.datetime.now()).total_seconds()
-25200.0

Need Your Help

Java Exceptions: exception myException is never thrown in body of corresponding try statement

java exception try-catch throws

I understand the idea of this error. But I guess I don't understand how this works down the call stack.

Same page Captcha validation using AJAX

php javascript ajax captcha

Ok, So i've been working on this code for a while now. I started with a preset code from SecurImages and have been tweaking it to try to validate the captcha AND submit the form. The catch is, ou...

How to calibrate UIAccelerometer?

objective-c ios accelerometer calibration

I am trying to calibrate my UIAccelerometer from ViewA but my Game view is ViewB. So pretty much what I want to achieve is lets say the user is playing on their side, I want my game to act like if ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.