<br><br><div><span class="gmail_quote">On 21 Dec 2005 01:43:13 -0800, <b class="gmail_sendername">Tim N. van der Leeuw</b> <<a href="mailto:tim.leeuwvander@nl.unisys.com">tim.leeuwvander@nl.unisys.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br><br>I want to parse strings containing date-time, which look like the<br>following:<br>
<br> "Mon Dec 19 11:06:12:333 CET 2005"<br>[snipped]<br>What I want to get is some sort of sortable date; either as a number or<br>(if nothing else) as a string in ISO8601 format.</blockquote><div><br>
Its slow in the office today, so: ......<br>
<br>
######<br>
<br>
from email import Utils<br>
import time<br>
<br>
zones = {'CET': '+0100', 'GMT': '0000', 'EST': '-0500', 'PST': '-0800'}<br>
<br>
def get_sortable_time(a_date):<br>
    split_date = a_date.split()<br>
<br>
    split_time = split_date[3].split(':')          # split the time<br>
    microsecs = float('0.'+ split_time[-1])   # get the microseconds<br>
    split_date[3] = ':'.join(split_time[:-1])    # join time, without microseconds <br>
    <br>
    split_date[4] = zones[split_date[4]]     # convert the timezone to '-0800' format<br>
    split_date = '
'.join(split_date)             
# eg "Mon Dec 19 11:06:12 +0100 2005"<br>
<br>
    gmt_time_as_num = Utils.mktime_tz(Utils.parsedate_tz(split_date) )   # eg 1134993972.0<br>
<br>
    return gmt_time_as_num + microsecs     # time in GMT,  eg 1134993972.33 <br>
        <br>
sortable_time = get_sortable_time( "Mon Dec 19 11:06:12:333 CET 2005" )<br>
<br>
print sortable_time          # = 1134993972.33  (in time.time() format )<br>
<br>
print time.ctime(sortable_time)          # Mon Dec 19 12:06:12 2005<br>
</div><br>
######<br><div><br>
You could remove the 2 "microsecs" references if you don't need that level of granularity<br>
<br>
 HTH :)<br>
</div><br></div>