Pav*_* S. 9 php format datetime date
有一个非常简单的问题.我有一个语言环境标识符,en,en_US,cs_CZ或其他.我只需要获取该语言环境的日期时间格式.我知道我可以根据语言环境轻松格式化任何时间戳或日期对象.但我只需要日期格式的字符串表示,让我们说一个正则表达式.是否有任何功能管理此功能?到目前为止我还没有发现任何...
Exapmle:
$locale = "en_US";
$format = the_function_i_need($locale);
echo $format; // prints something like "month/day/year, hour:minute"
Run Code Online (Sandbox Code Playgroud)
function getDateFormat($locale)
{
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
if ($formatter === null)
throw new InvalidConfigException(intl_get_error_message());
return $formatter->getPattern();
}
Run Code Online (Sandbox Code Playgroud)
确保您安装intl。
小智 3
从评论转换:
您将必须构建一个包含可能性列表的数组。
http://en.wikipedia.org/wiki/Date_format_by_country应该有所帮助。
完成后将函数发布到某个地方,我相信它对其他人来说会派上用场