What are the best practices for storing time values in a database and displaying them based on user time zones?

Storing time values in a database using UTC (Coordinated Universal Time) is a common best practice to ensure consistency across different time zones. When displaying these time values to users, you can convert them to the user's local time zone using PHP.

// Storing time values in the database using UTC
$timestamp = gmdate('Y-m-d H:i:s');

// Converting UTC time to user's local time zone
$user_timezone = new DateTimeZone('America/New_York'); // Example timezone
$datetime = new DateTime($timestamp, new DateTimeZone('UTC'));
$datetime->setTimezone($user_timezone);
$user_local_time = $datetime->format('Y-m-d H:i:s');

echo $user_local_time; // Displaying user's local time