laravel date() 期望参数 2 为整数,给出字符串 - 帮帮我
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40525316/
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
date() expects parameter 2 to be integer, string given - Help Me
提问by Kyaw Zin Wai
My Laravel 5.2 code is
我的 Laravel 5.2 代码是
$this->timestamp=date('Y-m-d',intval($timestamp));
$datetime=date('Y/m/d', $timestamp);
date() expects parameter 2 to be integer, string given
date() 期望参数 2 为整数,给出字符串
That error occur. But that error show when choose the day 31, not on other days (1 to 30). The other days are ok.
出现那个错误。But that error show when choose the day 31, not on other days (1 to 30). 其他日子还好。
When I change my code like that
当我像那样改变我的代码时
$this->timestamp=date('Y-m-d',intval($timestamp));
$datetime=date('Y/m/d', intval($timestamp));
Error solved but the date show is not correct. The date always show 1970/01/01Please help me, how to fix this?
错误已解决,但日期显示不正确。日期总是显示1970/01/01请帮帮我,如何解决这个问题?
采纳答案by Alexey Mezenin
Since you're using Laravel, you can do this with Carbon:
由于您使用的是 Laravel,因此您可以使用 Carbon 执行此操作:
Carbon::parse($timestamp)->format('Y-m-d');
回答by vikas pandey
try
尝试
$timestamp=date('Y-m-d',"1478774037");
echo $timestamp;
or
或者
$timestamp=date('Y-m-d',strtotime("31-07-2016"));
echo $timestamp;
回答by Shatadip
Try typecasting:
尝试类型转换:
$this->timestamp=date('Y-m-d',((int)$timestamp));
$datetime=date('Y/m/d', ((int)$timestamp));