方法 / laravel-date-international
laravel 日期处理工具
3.1.0
2020-10-30 14:40 UTC
Requires
- laravel/framework: ~5.0|^5.8|^6.0|^7.0|^8.0
- nesbot/carbon: ^1.0|^2.0
Requires (Dev)
- phpunit/phpunit: ~4.0|^8.0|^9.0
Suggests
- ext-intl: to use the component with locales other than "en"
README
使用本包,您可以在您的语言中轻松获取格式化的日期字符串。
演示
德语
Date:
20.08.15
20.08.2015
20. August 2015
Donnerstag, 20. August 2015
Time:
13:21
13:21:54 (with seconds)
Full:
20.08.15 13:21
20.08.2015 13:21
20. August 2015 13:21
Donnerstag, 20. August 2015 13:21
意大利语
Date:
20/08/15
20/ago/2015
20 agosto 2015
giovedì 20 agosto 2015
Time:
13:26
13:26:36 (with seconds)
Full:
20/08/15 13:26
20/ago/2015 13:26
20 agosto 2015 13:26
giovedì 20 agosto 2015 13:26:36 (with seconds)
英语
Date:
8/20/15
Aug 20, 2015
August 20, 2015
Thursday, August 20, 2015
Time:
1:25 PM
1:25:28 PM (with seconds)
Full:
8/20/15, 1:25 PM
Aug 20, 2015, 1:25 PM
August 20, 2015 at 1:25 PM
Thursday, August 20, 2015 at 1:25:28 PM (with seconds)
西班牙语
Date:
20/8/15
20/8/2015
20 de agosto de 2015
jueves, 20 de agosto de 2015
Time:
13:27
13:27:42 (with seconds)
Full:
20/8/15 13:27
20/8/2015 13:27
20 de agosto de 2015, 13:27
jueves, 20 de agosto de 2015, 13:27:42 (with seconds)
还有更多...
安装
语言
您可以使用以下方式查看所有可用的语言包
aptitude search language-pack-
安装一些语言
sudo apt-get install language-pack-de language-pack-en language-pack-es language-pack-it sudo locale-gen
检查您的可用语言
locale -a
确保您有类似这样的语言格式:de_DE
PHP 扩展
安装 php 国际化支持
sudo apt-get install php-intl
检查此扩展是否已包含
php -m | grep intl
Laravel
Laravel 使用 composer 需要此包
composer require approached/laravel-date-international
更新 composer 后,将 ServiceProvider 添加到 config/app.php 中的 providers 数组
Approached\LaravelDateInternational\ServiceProvider::class, and 'Dateintl'=> Approached\LaravelDateInternational\DateIntlFacade::class,
使用方法
Blade
Date:<br> {{ dateintl_date('short', $date) }}<br> {{ dateintl_date('medium', $date) }}<br> {{ dateintl_date('long', $date) }}<br> {{ dateintl_date('full', $date) }}<br><br> Time:<br> {{ dateintl_time($date) }}<br> {{ dateintl_time($date, true) }} (with seconds)<br><br> Full:<br> {{ dateintl_full('short', $date) }}<br> {{ dateintl_full('medium', $date) }}<br> {{ dateintl_full('long', $date) }}<br> {{ dateintl_full('full', $date, true) }} (with seconds)<br>
PHP
$str = Dateintl::full('short', $date);
日历
使用最后一个参数,您可以控制要使用哪个 日历
$str = Dateintl::full('short', $date, false, 'japanese');
可能的值包括
- 波斯
- 日本
- 佛教
- 中文
- 印度
- 伊斯兰
- 希伯来
- 科普特
- 埃塞俄比亚
许可
MIT