An identity for T-ordered exponentials with applications to quantum mechanics