I was testing some strings (countries) with the
strtotime()
function and foud out that :
- 'Poland' does returns a timestamp, but 'Soland' or anything else like this does not.
- 'GB' does too.
Going farther, 'a string' is also returning something, juste like some simple Letters like 'G' or 'P'.
Those strings are not listed in the datetime relative formats doc.
I might be dumb but I didn't find anything on those special cases, what is actually going on ?
And second less important question : how to actually check if a string is a valid date format excluding those "special" strings, knowing I don't know the format in advance ?
CodePudding user response:
DateTime accepts the same arguments as strtotime. The argument 'GB' used for DateTime shows that 'GB' is recognized as the time zone.
var_dump(new DateTime('GB'));
/*
object(DateTime)#3 (3) {
["date"]=>
string(26) "2021-09-24 16:54:37.568996"
["timezone_type"]=>
int(3)
["timezone"]=>
string(2) "GB"
}
*/
Like 'Poland', 'GB' is also represented in the list of Others time zones. 'Soland' not. DateTime then provides the current time ('Now') for a correctly recognized time zone.