php 格式化时间错误,PHP-格式化时间不起作用

我正在尝试获取工作时间格式.我正在使用继承的应用程序.

时间在表中存储为13:45:00

但是,它显示为1pm.我希望它显示为下午1:45

表中的数据存储在临时表中

$sql_temp="CREATE TEMPORARY TABLE IF NOT EXISTS cache (id int(11) NOT NULL,event_link text,

...

start_time varchar(255) NOT NULL,

start_time_a varchar(255) NOT NULL,

start_time来自显示为1pm的原始代码

start_time_a是我尝试显示小时数和子午线

然后读取带有开始日期的表格

$start_time=date('ga',strtotime($event->start_time));

$start_time_a = $event->start_time;

然后将其插入临时表

$ins_qu="INSERT INTO cache (id, . . . ,start_time,start_time_a) VALUES(

'".$start_time."',

'".$start_time_a."'

我提出了几种尝试使格式正确的方法

这给了我这样的结果

9pm || 21:45:00 || 6:00:21 pm CST **

晚上9点来自原始代码.

我相信21:45:00是拉弦的原始时间

下午6:00:21 CST是我尝试使用%r的strftime进行格式化的时间.

我需要怎么做才能显示hh:mm AM / PM?

解决方法:

首先通过strtotime将字符串转换为UNIX时间戳,然后使用date函数将其转换回所需的格式.

例如:

$Time = '05/12/2016 ' . $ve_n['start_time'];

$newDateTime = date('h:i A', strtotime($Time));

在您的示例中,它像:

输出为:

09:45 PM

或者使用g而不是h来显示前导零.

输出为:

9:45 PM

标签:strftime,strtotime,php

来源: https://codeday.me/bug/20191109/2012733.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值