PHP将mysql查询字符串转换为mm :ss time format

标签 php mysql datetime time formatting

我试图了解如何获取两个 mysql varchar 字符串之间的差异,它们的格式为 mm:ss,其中 m 代表分钟,s 代表秒。举个例子。

$a = 13:20;
$b = 13:00;

我要使用什么函数才能做到这一点

 $a - $b =  00:20 ?

$a = strtotime('13:20');
$b = strtotime('13:00');
echo "The time difference between 13:20 and 13:00 is : "  . ($a - $b);

Gives me 
The time difference between 13:20 and 13:00 is : 1200

Kindly take note of my original format. mm:ss

最佳答案

使用strtotime()

试试这个...

$time1 = explode(':', '13:20');
$time2 = explode(':', '13:00');

$a = 00 . ':' . $time1[0] . ':' . $time1[1];
$b = 00 . ':' . $time2[0] . ':' . $time2[1];

echo "The time difference between 13:20 and 13:00 is : "  . (strtotime($a) - strtotime($b));

关于PHP将mysql查询字符串转换为mm :ss time format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31226128/

相关文章:

php - 登录 Android 应用程序,密码存储在使用 PHP 密码哈希进行哈希处理的数据库中

mysql - 对MySQL结果进行排序,使两列中任意一列具有特定值的结果最后显示

python - 如何使用我自己的方法扩展 Python 的 datetime.datetime?

php - 可以在运行时在 php 中将函数分配给类变量吗?

php - 使用 php 读取 python 程序的实时输出

PHP FFmpeg视频宽高比问题

php - 从现有表条目中选择带有第一个选项的选项

PHP - 显示不同时区的数据

java - 如何使用 JPA 和 Hibernate 在 UTC 时区存储日期/时间和时间戳

php - 省略 Doctrine 生成的 SQL 的鉴别器部分