我正在尝试从不同的Carbon
和$date
变量创建$time
个实例。我现在正在使用以下代码。
$user->created_at = \Carbon\Carbon::parse($entry->Date." ".$entry->Time);
但我收到了这个错误。
In Carbon.php line 547:
DateTime::__construct(): Failed to parse time string (18/08/2017 10:49:50) at position 0 (1): Unexpected character
我还尝试删除$time
变量以检查它是否仅适用于$date
变量。但在这种情况下,我也遇到了这个错误:
In Carbon.php line 547:
DateTime::__construct(): Failed to parse time string (18/08/2017) at position 0 (1): Unexpected character
我还尝试使用"
函数修剪trim()
,以确保Carbon无法理解的字符不是"
。但它给了我相同的输出。
如何解决此错误?我试图找到互联网和其他堆栈溢出问题,他们建议我更新我的 Carbon 包,我做了。但是,它仍然给了我同样的错误。我无法弄清楚代码有什么问题。
更新:我也试过了strtotime($entry->Date);
,但仍然是,同样的错误!
答案 0 :(得分:2)
你可以使用它,
Carbon::createFromFormat('d/m/Y H:i:s', $entry->Date.' '.$entry->Time);
我希望这会有所帮助
答案 1 :(得分:0)
创建日期和时间的时间戳。之后,您可以使用Carbon
解析它们[-1.4222 -1.5083 -2.6488 -2.3428 -1.3167 -3.9615 -2.7804 -1.9563 -0.5054
-1.9524 -3.0026 -3.422 -2.1301 -2.0119 -2.1381 -2.2186 -2.0848 -2.4514
-1.9478 -2.3101 -2.4044 -1.9155 -1.569 -1.31 -1.4865 -2.3251 -1.7773
-1.304 -1.5215 -2.0634 -1.6987 -1.9217 -2.2863 -1.8166 -2.0219 -1.9594
-1.747 -2.1503 -2.162 -1.9507 -1.5971 -3.4499 -1.8946 -2.4328 -2.2415
-1.9045 -2.065 -1.9671 -1.8592 -1.6283 -1.7626 -2.2175 -2.1725 -3.7855
-5.1397 -3.6485 -4.4072 -2.2109 -2.048 -2.4887 -2.2324 -2.7897 -1.2932
-1.975 -1.516 -1.6127 -1.7135 -1.8243 -1.4887 -2.8973 -1.9656 -2.2236
-2.2466 -2.1224 -1.2247 -1.9657 -1.6138 -2.7787 -1.5004 -2.0136 -1.1001
-1.7226 -1.5829 -2.0317 -1.0834 -1.7444 -1.356 -2.3453 -1.7161 -2.2683
-2.2725 -0.4512 -4.5038 -2.0386 -2.1849 -2.4256 -1.5678 -1.8114 -2.2138
-2.2654 -1.8823 -2.7489 -1.8477 -2.1383 -1.6019 -2.84 -2.2595 -2.0764
-1.6758 -2.4279 -2.3489 -2.1884 -2.1888 -1.6289 -1.7358 -1.2989 -1.5656
-1.3362 -1.888 -2.1061 -1.4517 -2.0572 -2.4971 -2.2966 -2.6121 -2.4728
-2.8977 -1.7571 -2.4363 -1.4775 -1.7144 -2.047 -3.9252 -1.9907 -2.1808
-2.066 -1.9862 -1.4898 -2.3335 -2.6088 -2.4554 -2.4139 -1.7187 -2.2909
-1.4846 -1.8696 -2.444 -2.6253 -1.7738 -1.7192 -1.8737 -1.9977 -1.9948
-1.7667 -2.0704 -3.0147 -1.9014 -1.7713 -2.2551]