英文:
I got Not enough data available error with Carbon createFromFormat method
问题
我尝试使用Carbon将字符串中的日期时间值解析为"2020-09-17T14:08:59Z",但使用的格式是:
Carbon::createFromFormat($stringData, 'Y-m-d H:i:s')
我收到了错误消息:
Not enough data available to satisfy format {"exception":"[object] (Carbon\\Exceptions\\InvalidFormatException(code: 0): The format separator does not match
我应该使用哪种格式?
提前感谢!
英文:
I try to parse with carbon datetime value in sstring as "2020-09-17T14:08:59Z", but with format :
Carbon::createFromFormat($stringData,'Y-m-d H:i:s' )
I got error :
Not enough data available to satisfy format {"exception":"[object] (Carbon\\Exceptions\\InvalidFormatException(code: 0): The format separator does not match
Which format have I to use ?
Thanks in advance!
答案1
得分: 1
错误的参数顺序,以及错误的格式(使用\T
而不是空格来匹配您的分隔符,以及e
来获取时区)
Carbon::createFromFormat('Y-m-d\TH:i:se', $stringData)
或者你可以简单地让Carbon自动识别格式:
Carbon::parse($stringData)
英文:
Wrong parameters order, and wrong format (\T
instead of space to match your separator, and e
to get the timezone)
Carbon::createFromFormat('Y-m-d\TH:i:se', $stringData)
Or you can simply let Carbon find out the format:
Carbon::parse($stringData)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论