Search code examples
phpdatetimeformatlocale

How to determine if current locale has 24-hour or 12-hour time format in PHP?


This seems like a dumb question, but I've read the docs and couldn't find any straight-forward method.

I did something awful like:

$isTwentyFourByLocale = (substr(strftime('%X', mktime(16, 0, 0, 6, 15, 2010)), 0, 2) == 16);

Which works, but isn't there any better, straight-forward way?


Solution

  • Using your approach, it can be done shorter:

    $isTwentyFourByLocale = (substr(gmstrftime('%X', 57600), 0, 2) == 16);