def format_time():
    t = datetime.datetime.now()
s = t.strftime('%Y-%m-%d %H:%M:%S.%f')
tail = s[-7:]
f = round(float(tail), 3)
temp = '%.3f' % f
return '%s%s' % (s[:-7], temp[1:])
python datetime: Round/trim number of digits in microseconds