How to create a DateInterval from a time string
问题 If I have a time format string like "14:30:00" ("hours:minutes:seconds"), how do I get a DateInterval from the string? I can get a DateTime: $datetime= DateTime::createFromFormat("H:i:s","14:30:00"); But I need to add it to another DateTime object, and date_add needs a DateInterval. 回答1: If you want an interval that is 14 hours and 30 minutes, simply use the constructor... $interval = new DateInterval('PT14H30M'); To break it down... P - all interval spec strings must start with P (for Period