问题描述
使用Laravel将Carbon用作日期。 Carbon具有本地化支持。我一直在使用$date->locale($locale)->isoFormat('LL')
。
例如,对于中文,$date->locale('zh-CN')->isoFormat('L')
用于获取本地化数据。它返回1992年9月11日
。有什么方法可以获取带有区域设置编号的输出。
解决方法
在当前的2.41.5版本的Carbon中,中文没有"alt_numbers"
(可以使用translateNumber
来获取本地号码。例如日语:
https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Lang/ja.php#L93
您可以将其作为请求请求。
与此同时,您必须自己翻译:
$string = '1992年9月11日';
echo preg_replace_callback('/\d+/',static function ($number) {
// Here you can transform $number into an other representation according to your locale
return $number;
},$string);