What are the best practices for formatting and displaying timestamps retrieved from a MySQL database using PHP to ensure accurate date and time representation?

When retrieving timestamps from a MySQL database using PHP, it is important to format and display them correctly to ensure accurate date and time representation. One common practice is to use the PHP date() function along with the strtotime() function to convert the timestamp to the desired format. Additionally, setting the correct timezone using date_default_timezone_set() can help ensure accurate representation of the date and time.

// Retrieve timestamp from MySQL database
$timestamp = $row['timestamp'];

// Convert timestamp to desired format
$formatted_date = date('Y-m-d H:i:s', strtotime($timestamp));

// Set timezone
date_default_timezone_set('America/New_York');

// Display formatted date
echo $formatted_date;