问题
I have a website that allows people to post things. When they post, it gets inserted into the database and the database adds a timestamp.
When I hosted the database on my local machine, the timestamps were in my time zone. My new hosting website has it set to GMT time.
How can I make it display the time in my time zone? I've tried adding
date_default_timezone_set('America/New_York');
to my views just under the tag, but that doesn't help. Any ideas?
回答1:
// Set the time zone
$dateTimeZone = new DateTimeZone('America/New_York');
// Create the datetime and set the timestamp
$dateTime = new DateTime();
$dateTime->setTimestamp($timestamp);
// Convert it
$dateTime->setTimeZone($dateTimeZone);
echo $dateTime->format('m/d/Y H:i:s');
Should work I guess
来源:https://stackoverflow.com/questions/8114195/converting-date-from-database-to-a-different-timezone