Re: strptime and microseconds
On Oct 18, 10:54 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: On 18 oct, 13:46, mathieu [EMAIL PROTECTED] wrote: On Oct 18, 6:36 pm, mathieu [EMAIL PROTECTED] wrote: I am trying to use strptime to parse my microseconds but I was not able the documentation for it. The only list I found was: Ok final version is simply: s1 = 20070619 s2 = 115344.51 s3 = 115446.123456 ms2 = eval(s2) % 1 mms2 = int(ms2 * 100 + 0.5) ms3 = eval(s3) % 1 mms3 = int(ms3 * 100 + 0.5) s = s1 + s2 d1 = datetime(*strptime(s[:14], %Y%m%d%H%M%S)[0:6]) d1 = d1.replace(microsecond = mms2) What about this: py import datetime py s1 = 20070619 115344.025 py p1, p2 = s1.split(., 1) py d1 = datetime.datetime.strptime(p1, %Y%m%d %H%M%S) python2.3: from time import strptime py ms = int(p2.ljust(6,'0')[:6]) ljust padds with space only in python 2.3. But thanks anyway your solution is much cleaner ! -Mathieu -- http://mail.python.org/mailman/listinfo/python-list
strptime and microseconds
Hi there, I am trying to use strptime to parse my microseconds but I was not able the documentation for it. The only list I found was: http://docs.python.org/lib/module-time.html So I can get seconds with %S, but nowhere is there a microsecond symbol... Thanks for pointer to doc, -Mathieu s1 = 20070619 s2 = 150348.62 s = s1+s2 d = datetime(*strptime(s, %Y%m%d%H%M%S.%?)) -- http://mail.python.org/mailman/listinfo/python-list
Re: strptime and microseconds
On Oct 18, 6:36 pm, mathieu [EMAIL PROTECTED] wrote: On Oct 18, 6:00 pm, mathieu [EMAIL PROTECTED] wrote: Hi there, I am trying to use strptime to parse my microseconds but I was not able the documentation for it. The only list I found was: http://docs.python.org/lib/module-time.html So I can get seconds with %S, but nowhere is there a microsecond symbol... Thanks for pointer to doc, -Mathieu s1 = 20070619 s2 = 150348.62 s = s1+s2 d = datetime(*strptime(s, %Y%m%d%H%M%S.%?)) Getting closer... s1 = 20070619 s2 = 115344.51 s3 = 115445.123456 ms2 = eval(s2) % 1 mms2 = int(ms2 * 100 + 0.5) ms3 = eval(s3) % 1 mms3 = int(ms3 * 100 + 0.5) s = s1 + s2 d1 = datetime(*strptime(s[:12], %Y%m%d%H%M%S)[0:6]) d1.replace(microsecond = mms2) #print d1.microsecond s = s1 + s3 d2 = datetime(*strptime(s[:12], %Y%m%d%H%M%S)[0:6]) d2.replace(microsecond = mms3) #print d2.microsecond d = d2 - d1 print d.seconds print d.microseconds why would d.microseconds be 0 ?? Thanks, -Mathieu D'oh ! Ok final version is simply: s1 = 20070619 s2 = 115344.51 s3 = 115446.123456 ms2 = eval(s2) % 1 mms2 = int(ms2 * 100 + 0.5) ms3 = eval(s3) % 1 mms3 = int(ms3 * 100 + 0.5) s = s1 + s2 d1 = datetime(*strptime(s[:14], %Y%m%d%H%M%S)[0:6]) d1 = d1.replace(microsecond = mms2) # s = s1 + s3 d2 = datetime(*strptime(s[:14], %Y%m%d%H%M%S)[0:6]) d2 = d2.replace(microsecond = mms3) # d = d2 - d1 print d.seconds print d.microseconds sorry for the noise :)) -Mathieu -- http://mail.python.org/mailman/listinfo/python-list
Re: strptime and microseconds
On Oct 18, 6:00 pm, mathieu [EMAIL PROTECTED] wrote: Hi there, I am trying to use strptime to parse my microseconds but I was not able the documentation for it. The only list I found was: http://docs.python.org/lib/module-time.html So I can get seconds with %S, but nowhere is there a microsecond symbol... Thanks for pointer to doc, -Mathieu s1 = 20070619 s2 = 150348.62 s = s1+s2 d = datetime(*strptime(s, %Y%m%d%H%M%S.%?)) Getting closer... s1 = 20070619 s2 = 115344.51 s3 = 115445.123456 ms2 = eval(s2) % 1 mms2 = int(ms2 * 100 + 0.5) ms3 = eval(s3) % 1 mms3 = int(ms3 * 100 + 0.5) s = s1 + s2 d1 = datetime(*strptime(s[:12], %Y%m%d%H%M%S)[0:6]) d1.replace(microsecond = mms2) #print d1.microsecond s = s1 + s3 d2 = datetime(*strptime(s[:12], %Y%m%d%H%M%S)[0:6]) d2.replace(microsecond = mms3) #print d2.microsecond d = d2 - d1 print d.seconds print d.microseconds why would d.microseconds be 0 ?? Thanks, -Mathieu -- http://mail.python.org/mailman/listinfo/python-list
Re: strptime and microseconds
On 18 oct, 13:46, mathieu [EMAIL PROTECTED] wrote: On Oct 18, 6:36 pm, mathieu [EMAIL PROTECTED] wrote: I am trying to use strptime to parse my microseconds but I was not able the documentation for it. The only list I found was: Ok final version is simply: s1 = 20070619 s2 = 115344.51 s3 = 115446.123456 ms2 = eval(s2) % 1 mms2 = int(ms2 * 100 + 0.5) ms3 = eval(s3) % 1 mms3 = int(ms3 * 100 + 0.5) s = s1 + s2 d1 = datetime(*strptime(s[:14], %Y%m%d%H%M%S)[0:6]) d1 = d1.replace(microsecond = mms2) What about this: py import datetime py s1 = 20070619 115344.025 py p1, p2 = s1.split(., 1) py d1 = datetime.datetime.strptime(p1, %Y%m%d %H%M%S) py ms = int(p2.ljust(6,'0')[:6]) py d1.replace(microsecond=ms) datetime.datetime(2007, 6, 19, 11, 53, 44, 25000) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list