Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Re: Time Zone application after strptime?
M.-A. Lemburg
3/7/2008 9:44:00 PM
On 2008-03-07 22:24, Jim Carroll wrote:
> It's taken me a couple of hours to give up on strptime with %Z for recognizing
> time zones... but that still leaves me in the wrong zone:
>
> def paypal_to_mysql_date(ppDate):
> # a typical paypal date is 10:29:52 Feb 29, 2008 PST
> date_parts = ppDate.split()
> withouttz = " ".join(date_parts[:-1])
>
> # eventually we need to apply the timezone
> timezone = date_parts[-1]
>
> dt = datetime.strptime(withouttz, "%H:%M:%S %b %d, %Y")
> return dt.strftime("%Y-%m-%d %H:%M")
>
>
> How can I use the "PST" (or any other time zone name) to adjust dt by the
> correct number of hours to get it into UTC before storing in MySQL?
You could try mxDateTime's parser. It will convert most timezones
into UTC for you:
>>> from mx.DateTime import *
>>> DateTimeFrom('10:29:52 PST, Feb 29, 2008')
<mx.DateTime.DateTime object for '2008-02-29 18:29:52.00' at 2afdc7078f50>
However, note that I changed the position of the timezone in your
example.
Having the timezone at the end of the string and after the date
is a rather unusual format and not supported out-of-the-box by
mxDateTime (even though it does support a very wide range
of formats).
http://www.e...
products/python/mxBase/m...
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Mar 07 2008)
>>> Python/Zope Consulting and Support ...
http://www.e...
>>> mxODBC.Zope.Database.Adapter ...
http://zope.e...
>>> mxODBC, mxDateTime, mxTextTools ...
http://python.e...
________________________________________________________________________
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Time Zone application after strptime?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password