Home  >  Article  >  Backend Development  >  php将12小时制转换成24小时制的方法_PHP教程

php将12小时制转换成24小时制的方法_PHP教程

WBOY
WBOYOriginal
2016-07-13 09:58:431109browse

php将12小时制转换成24小时制的方法

 本文实例讲述了php将12小时制转换成24小时制的方法。分享给大家供大家参考。具体如下:

php将12小时制转换成24小时制,输入格式为:02:30:00 pm 转换成:14:30:00

1

2

3

4

5

6

7

8

9

10

11

function to_24_hour($hours,$minutes,$seconds,$meridiem){

$hours = sprintf('%02d',(int) $hours);

$minutes = sprintf('%02d',(int) $minutes);

$seconds = sprintf('%02d',(int) $seconds);

$meridiem = (strtolower($meridiem)=='am') ? 'am' : 'pm';

return date('H:i:s', strtotime("{$hours}:{$minutes}:{$seconds}{$meridiem}"));

}

echo to_24_hour( 1, 2, 3, 'pm' ); // Returns 13:02:03

echo to_24_hour( '02', '30', '00', 'pm' ); // Returns 14:30:00

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/977166.htmlTechArticlephp将12小时制转换成24小时制的方法 本文实例讲述了php将12小时制转换成24小时制的方法。分享给大家供大家参考。具体如下: php将12小时制...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn