[egenix-users] Re: Struggling to read a simple date text format
Simon Hook
simon.j.hook at jpl.nasa.gov
Sat Jul 15 10:58:50 CEST 2006
Many thanks. I would like to suggest you include:
from time import *
from mx.DateTime import *
c=Parser.DateTimeFromString("2005-05-05 10:10:10.00",('iso',))
print c
as an example in the documentation to help others.
S.
eGenix Support: M.-A. Lemburg wrote:
> [Please post such questions to egenix-users, so that others can benefit
> from the answers as well]
>
> Simon Hook wrote:
>
>> Hi,
>>
>> I have been trying to use DateTime but keep having problems with what I
>> think is a fairly standard format:
>>
>> "2005-05-05 10:10:10.00"
>> or
>> YYYY-MO-DD HH:MM:SS.ss
>>
>> its the fractional seconds that cause the problems. Below are some
>> examples that work and some that do not (examples "c" and "d", examples
>> that fail are commented out). Any idea how to get "c" and "d" to work? I
>> think "c" should work and there has to be some literal to tell strptime
>> to ignore a character but I cannot find it.
>>
>> Many thanks,
>>
>> Simon
>>
>> ------
>>
>> from time import *
>> from mx.DateTime import *
>>
>> a=ISO.ParseDateTimeUTC("2005-05-05 10:10:10.00")
>> print a
>>
>> b=Parser.DateTimeFromString("2005-05-05 10:10:10.00")
>> print b
>>
>> # This fails
>> #c=Parser.DateTimeFromString("2005-05-05 10:10:10.00",'iso')
>> #print c
>>
>
> This should read:
>
>
>>>> c=Parser.DateTimeFromString("2005-05-05 10:10:10.00",('iso',))
>>>> print c
>>>>
> 2005-05-05 10:10:10.00
>
>
>> # This fails
>> # d=strptime("2005-05-05 10:10:10.00","%Y-%m-%d %H:%M:%S")
>> # print d
>>
>
> This doesn't work, since the strptime %S parser doesn't support
> fractions, mainly because the structure which strptime
> returns uses integers for the seconds part.
>
>
More information about the egenix-users
mailing list