In terms of best practices, is it advisable to create a separate utility function or class for handling date formatting and localization in PHP applications?

When working with date formatting and localization in PHP applications, it is advisable to create a separate utility function or class to handle these tasks. This helps to centralize the logic for formatting dates and managing localization settings, making it easier to maintain and reuse across the application.

class DateUtils {
    public static function formatDate($date, $format = 'Y-m-d H:i:s', $locale = 'en_US') {
        $dt = new DateTime($date);
        $dt->setTimezone(new DateTimeZone('UTC'));
        $dt->setTimezone(new DateTimeZone($locale));
        return $dt->format($format);
    }
}

// Example of formatting a date using the DateUtils class
$date = '2022-01-15 13:30:00';
$formattedDate = DateUtils::formatDate($date, 'Y-m-d', 'fr_FR');
echo $formattedDate; // Output: 2022-01-15