当天时间和秒数的互相转换


/**
* 当天时间和秒数的互相转换
*/
public static function timeSecondsTranslates($value, $time2seconds = true, $format = "H:i")
    {
        if ($time2seconds) {
            $parsed = date_parse($value);
            $seconds = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second'];
            return $seconds;
        } else {
            return gmdate($format, $value);
        }
    }

使用

$data['start_time'] = self::timeSecondsTranslates($data['start_time'], true);
$data['end_time'] = self::timeSecondsTranslates($data['end_time'], true);
if ($data['start_time'] >= $data['end_time']) {
    throw new CErrorException('结束时间不能小于开始时间');
}

 

posted @ 2019-04-22 15:45  四川人  阅读(587)  评论(0编辑  收藏  举报