返回两个(日期和时间)PHP之间的时差

编程入门 行业动态 更新时间:2024-10-10 08:19:39
本文介绍了返回两个(日期和时间)PHP之间的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试了堆栈溢出时可用的大部分功能,但似乎没有任何作用.

i tried most of what is available on stack overflow but none seem to work.

我尝试比较两种方式(日期和时间格式).并计算它们之间的差异是否在5秒钟之内

any way i am trying to compare two (date and time formats). and calculate whether their difference is within 5 seconds of each other

第一个日期是当前日期:

the first date is the current date:

$today = date("Y-m-d H:i:s");

第二个日期取自mysql数据库:

the second date is taken from mysql database:

$result = mysql_query("SELECT * FROM BUS_DATA where BusRegID = 'bus'") or die(mysql_error()); $row = mysql_fetch_array($result); $update_date = $row["update_date"];

答案应分为年,月,日,小时,分钟和秒.

the answer should be segmented into years , month , days , hours , minutes ,and seconds portions.

我正在运行PHP版本5.3.3

I am running PHP Version 5.3.3

大多数答案只给出时间范围内的结果,我想检查日期是否匹配,然后比较一天中的时间是否在5秒以内,所以请比你们提前:)

most answers give result in time frame only , I want to check whether the date matches , then compare if the time of the day is within 5 seconds , than you guys in advance :)

推荐答案

使用strtotime,它几乎可以理解任何日期格式:

use strtotime, it's understands almost any date formats:

$timeDiff = abs(strtotime($today) - strtotime($update_date));

这为您提供了以秒为单位的日期之间的时差.

this gives you the difference between dates in seconds.

更多推荐

返回两个(日期和时间)PHP之间的时差

本文发布于:2023-11-22 07:58:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时差   日期   两个   时间   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!