If you need milliseconds and dates in one object, use the datetime object. Unfortunately, there is no date and time analyzer in the format you give. You can use a simple regular expression:
import time, datetime, re dt_pat = re.compile(r"(\d+)\-(\d+)-(\d+)\s+(\d+):(\d+):(\d+),(\d+)") def mstime( tstr ): m = dt_pat.match( tstr ) if m==None: return m v = [int(s) for s in m.groups()] return datetime.datetime(*v) t1 = "2013-09-13 15:43:35,893" t2 = "2013-09-13 15:43:45,147" dt1 = mstime( t1 ) dt2 = mstime( t2 ) diff = dt2-dt1 print diff.total_seconds()
source share