gpt4 book ai didi

php - 碳12小时格式

转载 作者:行者123 更新时间:2023-11-29 09:55:48 25 4
gpt4 key购买 nike

我的数据库中有一些日期,我想以 12 小时格式显示它们,最后是 AM - PM。我使用的是carbon,我的代码是这样的:

$hora = Carbon::createFromFormat('h:i A', $fecha_inicio, 'UTC')->setTimeZone($timeZone)->format('h:i A');

$fecha_inicio 类似于 2018-11-02 13:47:03

但这会引发错误:** 小时不能高于 12**

最佳答案

来自docs :

h 12-hour format of an hour with leading zeros 01 through 12

H 24-hour format of an hour with leading zeros 00 through 23

因此,请使用 H:i 而不是 h:i

$hora = Carbon::createFromFormat('Y-m-d H:i:s', $fecha_inicio, 'UTC')->setTimeZone($timeZone)->format('h:i A');

createFromFormat 中的第一个参数是您在 $fecha_inicio 中已有的格式

关于php - 碳12小时格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53889451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com