Timezone and ISO8601 struggles with datetime and xml.utils.iso8601.parse



Hello,

I am trying to convert a local time into UTC ISO8601, then parse it
back into local time. I tried the following:

----------------------
#!/usr/bin/python
import time
import datetime
import xml.utils.iso8601

year = 2005
month = 7
day = 22
hour = 10 # This is localtime
minute = 30

mydatetime = datetime.datetime(year, month, day, hour, minute)
strtime = mydatetime.isoformat()

print "Time: " + strtime # Localtime too
mytimestamp = xml.utils.iso8601.parse(strtime)
----------------------

How can I convert this into UTC? Commonsense would have me guess that
the date is converted into UTC on construction of the datetime object,
hovever, this doesn't seem to be the case. I also found the
astimezone(tz) method, but where can I obtain the concrete tz object?

The second problem has to do with the ISO8601 parser, which raises the
following error:

----------------------
Traceback (most recent call last):
File "./timetest.py", line 16, in ?
mytimestamp = xml.utils.iso8601.parse(strtime)
File "/usr/lib/python2.4/site-packages/_xmlplus/utils/iso8601.py",
line 22, in parse
raise ValueError, "unknown or illegal ISO-8601 date format: " + `s`
ValueError: unknown or illegal ISO-8601 date format:
'2005-07-22T10:30:00'
----------------------

Why does it fail to parse the value returned by the datetime object,
and how can I create a parseable time from the datetime object?

Thanks,
-Samuel

.



Relevant Pages

  • Re: Web services and incorrect handling of time zones in DateTime
    ... You are not the first one writing this, I think that it is an error by design. ... when the SOAP message contains datetime like ... exactly the same time as previously, but in UTC), it becomes DateTime ... the UTC time should be converted to local time ...
    (microsoft.public.dotnet.general)
  • Re: System.TimeZone interface unusable?
    ... ToLocalTime must be "A DateTime instance whose value is the local time ... as the parameter states "a UTC time". ... serializer documentation is the only other place the Kind property is ...
    (microsoft.public.dotnet.framework)
  • Re: UTC conversion from different time zones
    ... but in my idea is the time in Net not real calendar based. ... But if you take something which is already UTC (because you've called ... I find the dateTime pretty good. ... DateTime had no idea whether it was a local time or a universal time - ...
    (microsoft.public.dotnet.general)
  • Re: Time zones dates in vb.net 2005
    ... I have set the region on 1 computer to 'Perth Australia' and the other is on ... Store UTC only. ... know at which local time offset it has been stored. ... you can always use and calculate with the UTC datetime values. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: What time is it? Issues with Local time, system time, DST
    ... Apparently CE stores time in local time, ... be for local time, not UTC. ... RTC, so that when processor is asleep or off, onboard batteries ... you can't know the UTC unless you also have, in some non-volatile ...
    (microsoft.public.windowsce.platbuilder)