/**
* ('2021-11-11')->1636560000
* (1636560000)->'2021-11-11 00:00:00'
* (1636560000,'date')->'2021-11-11'
* ('+1 day')->'2021-11-12 14:00:00'
* ('+1 day','time')->'14:00:00'
*/
function now($st=null,$format=null){
$f = $format=="date" ? "Y-m-d" : ($format=="time" ? "H:i:s" : "Y-m-d H:i:s");
if(empty($st)){
return date($f);
}else if(is_numeric($st)){
return date($f, $st);
}else if(strtotime($st)!==false){
if($format==null && preg_match('/[^0-9-:]/',str_replace(' ','',$st))==0){
return strtotime($st);
}else{
return date($f, strtotime($st));
}
}else{
return false;
}
}
|