如何在 Laravel 5.5 中使用 Carbon 2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53202646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Use Carbon 2 In Laravel 5.5
提问by KATJ Srinath
I am using Laravel 5.5and it has Carbon version 1.27which has no function like
我使用的是Laravel 5.5,它的Carbon 版本为 1.27,没有类似的功能
- roundHour()
roundMinute()
which are added in Carbon version 2.
- 整点()
回合分钟()
这是在Carbon 版本 2中添加的。
I was trying to update the Carbon version through composer but no success
我试图通过作曲家更新 Carbon 版本但没有成功
How can I use Carbon's New version in my Laravel 5.5
如何在我的 Laravel 5.5 中使用 Carbon 的新版本
回答by Sapnesh Naik
Carbon update is due in Laravel 5.8till then the work-around is using laravel-carbon-2adapter for Laravel.
碳更新将在 Laravel 5.8 中到期,直到那时解决方法是使用Laravel 的 laravel-carbon-2适配器。
Basically, add the following dependencies to your composer.json:
基本上,将以下依赖项添加到您的composer.json:
{
...
"require": {
...
"kylekatarnls/laravel-carbon-2": "^1.0.0",
"nesbot/carbon": "2.0.0-beta.2 as 1.25.0"
}
...
}
Then run:
然后运行:
composer update
回答by Dendi Handian
Check the latest version of carbon 2 and the latest version of adapter in https://carbon.nesbot.com/#gettingstarted, the instruction to upgrade carbon 1 to 2 is also there.
在https://carbon.nesbot.com/#gettingstarted 中查看 carbon 2 的最新版本和适配器的最新版本,其中还有将 carbon 1 升级到 2 的说明。