How to convert 12-hour clock to 24-hour clock in php, php24-hour_PHP tutorial

WBOY
Release: 2016-07-13 09:58:54
Original
907 people have browsed it

How to convert 12-hour clock to 24-hour clock in php, php24 hours

This article describes the method of converting 12-hour clock to 24-hour clock in php. Share it with everyone for your reference. The details are as follows:

php converts 12-hour clock to 24-hour clock. The input format is: 02:30:00 pm converted to: 14:30:00

<&#63;php
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') &#63; '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
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/976687.htmlTechArticleHow to convert the 12-hour clock into the 24-hour clock in php, php24 hours This article explains how to convert the 12-hour clock into the 12-hour clock in php How to convert to 24-hour format. Share it with everyone for your reference. The details are as follows:...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template