datetime - 为什么碳助手不起作用并给出日期时间错误?
问题描述
这个应用程序内置在 Lavavel 5 中。我有一个包含出生日期、月份和年份值的表格。我使用此查询查询表:
$tarikh = DB::table('itemregistrations')
->select('itemregistrations.lahir_dd', 'itemregistrations.lahir_mm', 'itemregistrations.lahir_yy')
->get();
dd($塔里克);产生这个输出:
Collection {#709 ▼
#items: array:1123 [▼
0 => {#681 ▼
+"lahir_dd": 9
+"lahir_mm": "June"
+"lahir_yy": 1979
}
1 => {#670 ▶}
2 => {#680 ▶}
3 => {#713 ▶}
我想使用碳计算年龄并使用数组映射作为年龄插入集合:
$tarikh->map(function ($detail) {
$detail->age = \Carbon\Carbon::parse($detail->lahir_yy)->diffInYears();
return $detail;
});
但是出现了这个错误:
DateTime::__construct(): Failed to parse time string (0) at position 0 (0): Unexpected character
它突出显示了这段代码:
parent::__construct($time, $timezone);
if (isset($locale)) {
setlocale(LC_NUMERIC, $locale);
}
一位朋友帮助我使用了这个小提琴并且工作正常..但是在应用程序中,出现了错误。
https://implode.io/i1GanD
有谁知道这个冲突错误的原因是什么?试图搜索相同的问题,但仍然没有解决方案。谢谢
解决方案
通过将代码更改为:
$tarikh->map(function ($detail) {
$detail->Umur = \Carbon\Carbon::createFromFormat('Y',$detail->lahir_yy)->diffInYears();
return $detail;
});
推荐阅读
- html - 如何将嵌入的 html 标签执行到像这样的角度值绑定中:{{variable}}?
- java - 确保接收到的 Rabbit MQ 事件的顺序
- encryption - 如何以编程方式解密 Vault 生成的 AES256-GCM96 密文并导出 Vault 密钥?
- angular - 给出角度路由器参数而不在 url 中
- sql-server-2008 - 如何使用 SSMS 连接到 MS Dynamics 365 CRM
- javascript - 如何将滚动高度设置为数组长度?
- imagemagick - 如何在 TYPO3 安装工具中调试 ImageMagick 图像处理?
- java - 在 TabLayout 和 ViewPager2 中执行异步任务后更新具有相同布局的多个片段
- java - 不能在 child() 中为参数 'pathString' 传递 null 这个问题的解决方案是什么?问题出在位置
- flutter - 不能循环遍历列表
并显示在 DataTable 中