def round_to_seconds(dt):
 rounding = 0
 if (dt.microsecond >= 500000):
  rounding = 1
 return (dt + datetime.timedelta(0, rounding, (- dt.microsecond)))

def round_to_seconds ( dt ) : rounding = 0 if ( dt . microsecond >= 500000 ) : rounding = 1 return ( dt + datetime . timedelta ( 0 , rounding , ( - dt . microsecond ) ) )
round a datetime to the nearest second .