Home > Backend Development > PHP Tutorial > 24-hour timekeeping method time implementation program in PHP_PHP tutorial

24-hour timekeeping method time implementation program in PHP_PHP tutorial

WBOY
Release: 2016-07-13 17:14:27
Original
1320 people have browsed it

How to get the 24-hour time in PHP? Use a custom function provided in this article to obtain the current time, and the time calculated using the 24-hour clock method is used.

The code is as follows
 代码如下 复制代码

function getTime() {
  $time="";
  //上午时间
  $h1=date("h")>12?(date("h")-12):date("h");
  //下午时间
  $h2=((date("h")+12)>=24)?date("h"):(date("h")+12);

//判断是否为上午
  if(date("a")=="am") {
       $time=date("Y-m-d $h1:i:s");
  } else { //判断是否为下午
       $time=date("Y-m-d $h2:i:s");
  }

 return $time;

}

Copy code
function getTime() {
$time="";
//Morning time
$h1=date("h")>12?(date("h")-12):date("h");
//Afternoon time
$h2=((date("h")+12)>=24)?date("h"):(date("h")+12);

//Judge whether it is morning
if(date("a")=="am") {
         $time=date("Y-m-d $h1:i:s");
} else { //Determine whether it is afternoon
        $time=date("Y-m-d $h2:i:s");
}

}
http://www.bkjia.com/PHPjc/628993.html
www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/628993.htmlTechArticleHow to get the 24-hour time in PHP? Use a custom function provided in this article to obtain the current time, and the time calculated using the 24-hour clock method is used. The code is as follows Copy code...
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