如何将hh:mm:ss转换为分钟 [英] How to convert hh:mm:ss to minutes

查看:263
本文介绍了如何将hh:mm:ss转换为分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个时间列$data['Time'] (hh:mm:ss),我需要将其转换为分钟.我怎样才能做到这一点?当我这样写时:

I have a time column $data['Time'] (hh:mm:ss) and I need to convert it to minutes. How can I do this? When I am writing like this:

$avg = ($data['Kilometers'] / $data['Time']) * 60;

我有这个错误

Warning: Division by zero in ... on line ..

推荐答案

$time    = explode(':', $data['Time']);
$minutes = ($time[0] * 60.0 + $time[1] * 1.0);
$avg     = $minutes > 0 ? $data['Kilometers'] / $minutes : 'inf'; // if time stored is 0, then average is infinite.

将时间戳转换为分钟的另一种方法是

Another way to convert the timestamp to minutes is,

$time    = date('i', strtotime($data['Time']));

这篇关于如何将hh:mm:ss转换为分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆