【问题标题】:"DateTime::__construct(): Failed to parse time string (05 December 2012 - 09:30 AM) at position 17 (-): Unexpected character"“DateTime::__construct():无法在位置 17 (-) 解析时间字符串(2012 年 12 月 5 日 - 上午 9:30):意外字符”
【发布时间】:2019-11-02 02:28:37
【问题描述】:
$start = Carbon::parse($request->date1);
$end = Carbon::parse($request->date2);
$allSchedules = $allSchedules->where('dateTime','<=',$end)->where('dateTime','>=',$start);

"DateTime::__construct(): 解析时间字符串失败(12 月 5 日 2012 - 09:30 AM)在位置 17 (-):意外字符"

【问题讨论】:

  • 请更新您的问题以包含所有相关信息。请阅读官方Help 了解如何提出好的问题。

标签: laravel


【解决方案1】:

正如错误所说,从您发送给 Carbon 构造的日期中删除破折号 (-)。

来自客户端,或者直接在 parse 方法上:

$start = Carbon::parse(str_replace('-', '', $request->date1));

【讨论】:

    猜你喜欢
    • 2020-10-16
    • 2021-06-09
    • 2019-09-07
    • 2022-01-16
    • 2013-06-29
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    相关资源
    最近更新 更多