$date = new DateTime('2021-06-12'); $date->setTime(10, 30, 0); echo $date->format('Y-m-d H:i:s'); // output: 2021-06-12 10:30:00
$date = new DateTime(); $date->setTime(16, 0, 0); echo $date->format('Y-m-d H:i:s'); // output:In this example, we created a new DateTime object with the current date-time and used the setTime method to set the time component to 16:00:00. We then used the format method to display the formatted date-time string. The DateTime class is built-in PHP class, thus no installation of any package is required.16:00:00