Python Equivalent??

scummer scummer at 3squares.com
Tue Mar 9 16:53:26 EST 2004


Hi,

I am trying to rewrite the following java method:

public static long convertDateTime(String d, String pattern) throws
Exception {
     SimpleDateFormat sdf = new SimpleDateFormat(pattern);
     sdf.setTimeZone(new SimpleTimeZone(0,""));
     java.util.Date date = sdf.parse(d);
     return date.getTime();
}

into Python and not having a great amount of luck. Simply put, I need
to pass the method a datetime string, with a given pattern, and have
the timezone set on it to UTC--without changing the time value. For
example, if I pass these values:

d = "2001-01-01 13:00:00"
pattern = "%Y-%m-%d %H:%M:%S"

to the python function:

def convertDateTime(self, d, pattern):

and I am doing so from timezone "Europe/Berlin" for example, I do not
want the "13" to be changed to "12" before this value is compared to
the Unix Epoch (which is at 01 January, 1970 @ 00:00:00 UTC if I
understand correctly). I want it to remain 13:00:00 UTC.

The return value has to be milliseconds from the Unix epoch (like the
Java's getTime()).

I have fooled around with the default python modules datetime and time
and looked at mx.DateTime but still have not decyphered it yet. Anyone
care to lend me some assistance?

Thanks in advance,

Scum



More information about the Python-list mailing list