用于将时间转换为秒数的功能

Bri*_*ian 7 php mysql

在我们的网站上,我们有很多游泳时间,我们希望转换为秒.即1:23:33.03或58:22.43.有没有PHP功能可以做到这一点?MySQL功能?

zer*_*kms 11

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_time-to-sec

mysql> SELECT TIME_TO_SEC('22:23:00');
    -> 80580
mysql> SELECT TIME_TO_SEC('00:39:38');
    -> 2378
Run Code Online (Sandbox Code Playgroud)


jas*_*bar 8

function time2seconds($time='00:00:00')
{
    list($hours, $mins, $secs) = explode(':', $time);
    return ($hours * 3600 ) + ($mins * 60 ) + $secs;
}
Run Code Online (Sandbox Code Playgroud)

这里开始.

MySQL也有TIME_TO_SEC()


Ser*_*rgi -1

Strtotime就是您所需要的。您将获得一个 Unix 时间戳,在本例中为秒数。