有一个很简单的问题。我有一个语言环境标识符,en、en_US、cs_CZ 或其他。我只需要获取该语言环境的日期时间格式。我知道我可以根据语言环境轻松格式化任何时间戳或日期对象。但我只需要日期格式的字符串表示,比方说一个正则表达式。是否有管理此功能的功能?目前还没有找到...
例子:
$locale = "en_US";
$format = the_function_i_need($locale);
echo $format; // prints something like "month/day/year, hour:minute"
最佳答案
function getDateFormat($locale)
{
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
if ($formatter === null)
throw new InvalidConfigException(intl_get_error_message());
return $formatter->getPattern();
}
确保安装 intl .
关于php - 根据 PHP 语言环境获取日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8827514/