Let's say the user can submit their time as strings in one of multiple formats. Is there any way in DateTime::createFromFormat()
to specify multiple formats to parse.
Right now I notice if you specify a format, any missing elements cause an error.
For example, lets say I'm accepting both 1h22m34s
and a 21m22s
as valid time strings (the second implies 00h
, but doesn't require it).
The following will throw an error on the second string when seen:
$mytime = `21m22s`;
echo DateTime::createFromFormat('H\hi\ms\s',$mytime)->format('H:i:s');
How can I work to allow it to parse multiple formats?
Or is there another, non-hack way to work with multiple formats?