$dateString = '2022-07-22'; $date = DateTime::createFromFormat('Y-m-d', $dateString); echo $date->format('F j, Y'); // Output: July 22, 2022 $timeString = '2022-07-22 10:30:00'; $time = DateTime::createFromFormat('Y-m-d H:i:s', $timeString); echo $time->format('g:i A'); // Output: 10:30 AMIn these examples, we used the `createFromFormat()` method to parse a date and a time string into `DateTime` objects. We first specified the format of the string, and then passed it as the second parameter to the `createFromFormat()` method. We then used the `format()` method to output the date and time in a different format. The `DateTime` class is part of the PHP core library and does not require any additional package or library to use.