duancheng1955 2015-11-09 19:35
浏览 191
已采纳

Php检查时间字符串整小时是否像“上午8:00”

I have series of time strings like "8:00am", "8:15am", "8:30am" I also have timestamps for these times as keys of the arrays where as times are values so array would be like this:

Note: Timestamps are dummy in this example

array(
144441415=>"8:00am", 
1444784744=>8:30am
...
.....
);

I would like to know if hour is whole hour for example "8:00am", "9:00am" are whole hours but "8:45am" or "9:30am" are not whole hours. I would like to filter whole hours from array as mentioned above. Thanks.

  • 写回答

3条回答 默认 最新

  • dsfjk44656 2015-11-09 19:53
    关注

    Thank you Rudie I was able to get whole hour from number of seconds, thank you for your hint, so I did something like this:

    //Loop through each hour of the day by getting both key and value
    foreach( $hours_of_day $timestamp=>$time_string )
    {
        //If timestamp mod by number of seconds in hours is zero this means whole hour
        if( ($timestamp%3600) == 0 )
        {
            echo "Whole hour = $timestring<br />";
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制