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");
}
return $time;
}
http://www.bkjia.com/PHPjc/628993.htmltruehttp: //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...
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