如何在Laravel中获得具有语言环境数字的Carbon本地化日期?

问题描述

使用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);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...