How can PHP developers efficiently handle and display time durations in a user-friendly format on web applications?

When handling and displaying time durations in a user-friendly format on web applications, PHP developers can use the DateTime class to easily calculate and format time differences. By utilizing the DateTime class methods such as diff() and format(), developers can accurately calculate time durations and present them in a human-readable format.

// Example code snippet to calculate and display time duration in a user-friendly format

$startTime = new DateTime('2022-01-01 12:00:00');
$endTime = new DateTime('2022-01-01 14:30:00');

$interval = $startTime->diff($endTime);

echo $interval->format('%h hours %i minutes'); // Output: 2 hours 30 minutes