doubianyan9749 2016-12-29 03:15
浏览 35

我怎样才能在时间组合框中添加am / pm

I have the time combobox with 30 minutes increment but I am unable to add am/pm in that.

This is the current time format showing (12:00, 12:30, 01:00, 01:30). I want to display time like (12:00pm, 12:30pm, 01:00am, 01:30am).

My code is below:

for($hours=0; $hours<24; $hours++) // the interval for hours is '1'
    for($mins=0; $mins<60; $mins+=15) // the interval for mins is '30'
echo '<option value="'.str_pad($hours,2,'0',STR_PAD_LEFT).':'.str_pad($mins,2,'0',STR_PAD_LEFT).'">'.str_pad($hours,2,'0',STR_PAD_LEFT).':'.str_pad($mins,2,'0',STR_PAD_LEFT).'</option>';
  • 写回答

1条回答 默认 最新

  • doulou0882 2016-12-29 03:21
    关注

    Try adding the following inside your second for

    $ampm = ($hours >= 12) ? 'pm' : 'am';
    

    then concat the $ampm to your string.

    This won't give you 1:00pm, though, it will give you 13:00 pm based on your current code, so you'll also need to address that

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大