laravel 使用 Carbon 更改日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46485838/
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
Change Date format using Carbon
提问by scott
I am using Laravel framework and for date conversion using Carbon package
我正在使用 Laravel 框架并使用 Carbon 包进行日期转换
I am unable convert date format to mysql format.I have following code
我无法将日期格式转换为 mysql 格式。我有以下代码
$request->event_start_date
will have 25/08/2017
$request->event_start_date
会有 25/08/2017
print_r(carbon::parse($request->event_start_date));
when $request->event_start_date
is 03/08/2017
then it will print as
当$request->event_start_date
被03/08/2017
那么它将打印成
Carbon\Carbon Object( [date] => 2017-03-08 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC)
But if date is 25/08/2017
then it will throw erorr as
但是如果日期是25/08/2017
那么它会抛出错误
"G:\XAMPP\htdocs\myproject\vendor\nesbot\carbon\src\Carbon\Carbon.php" line : 291 message : "DateTime::__construct(): Failed to parse time string (25/08/2017) at position 0 (2): Unexpected character"
“G:\XAMPP\htdocs\myproject\vendor\nesbot\carbon\src\Carbon\Carbon.php”行:291 消息:“DateTime::__construct(): 无法解析时间字符串 (25/08/2017) at位置 0 (2):意外字符”
need to convert 25/08/2017
to Mysql date format.I have tried a lot to fix this .finaly posted here so that i get some help from you
需要转换25/08/2017
为 Mysql 日期格式。我已经尝试了很多来解决这个问题。finaly 在这里发布,以便我从你那里得到一些帮助
Thanks
谢谢