The variable $time can be the next time ( 0:12 , 01:22 , etc.). When splitting a string, I get $time[0]==0 or 01 . Am I checking for the presence of a single digit in this variable?

 $time=explode(":",$value); print_r($time); if($time[0]<=10 and strlen($time[0])==1){ $minutes="0".$time[0]; }else{ $minutes=$time[0]; } 
  • one
    And what's stopping you from independently verifying the correct operation of this piece of code with various inputs? - Kromster
  • one
    Indeed, write unit tests and check. Keep the @Kromster question. - Nick Volynkin

2 answers 2

DateTime object. http://php.net/manual/en/class.datetime.php

 $dateTime = DateTime::createFromFormat('H:i', $time); $minutes = $dateTime->format('i'); 

Time Formats http://php.net/manual/en/function.date.php

  • substituted values ​​does not work writes Call to a member function format ()
  • @ G_test_00 Yes, I thought that the original data is minutes: seconds. Minutes and seconds should contain 2 numbers. And if it's hours: minutes, then it will work. For hours, the 1st character is enough. I corrected the answer. - newage
 $dateTime = strtotime($time); echo date('H:i',$dateTime);