Determining the lifetime of long-lived particles at the LHC