php时间字符串(导零)格式化
function time_formatting($time=''){ if(preg_match("/^([0-9]{1,2}):([0-9]{1,2})$/", $time)) { list($hour, $minute) = explode(":", $time); if($hour > 23 || $minute >59) return ['code' => 1,'msg' => LG('Incorrect time format')]; if ($hour < 10 && strlen($hour) == 1) { $hour = '0' . $hour; // 添加前导零 } if ($minute < 10 && strlen($minute) == 1) { $minute = '0' . $minute; // 添加前导零 } $fullTime = date('H:i', strtotime(date('Y-m-d') . ' ' . $hour . ':' . $minute)); return ['code' => 0,'msg' => '成功','time' => $fullTime]; } return ['code' => 1,'msg' => '失败']; }