Pergunta

I am converting a bunch of dates in a database into unixtimestamp in python. There are entries in the database written like:

Thu Jun 16 10%3A08%3
Wed Jun 8 09%3A39%3A

Can any one tell me what this means? And possibly how to convert this over into a unixtimestamp?

Any other dates such as: Thu Oct 14 15:11:47 I just use strptime to convert it over, but the ones above are giving me issue.

Thanks!

Foi útil?

Solução

The '%3A' bits are the url encoded representation of a colon :. You can use the urllib.unquote() function to decode those strings:

>>> urllib.unquote("Wed Jun 8 09%3A39%3A")
'Wed Jun 8 09:39:' 

...but it looks like the dates got stored in a fixed-length field and the seconds have been truncated.

Outras dicas

I think you need urllib.unquote here:

>>> import urllib
>>> urllib.unquote('Thu Jun 16 10%3A08%3')
'Thu Jun 16 10:08%3'
>>> urllib.unquote('Wed Jun 8 09%3A39%3A')
'Wed Jun 8 09:39:'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top