我使用Carbon的createFromFormat方法时出现了“数据不足”的错误。

huangapple go评论54阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年7月13日 22:17:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定