简体   繁体   中英

Converting a MySQL database row time timezone

So I have made something ridiculously complicated by accident because I don't think you can have individual timezones per database in MySQL if they're on the same account?

Basically most of my databases are for American users and use one of the American timezones, I then also run an English blog.

My issue is that the English blog has the correct BST (GMT+1) value inserted into the datetime row but it's in the database that uses the MDT timezone.

I then need to get that time for an rss feed using:

$date = date('r', $data['date']); //MDT system but $data['date'] is GMT+1

but this gives me a time in the future at the time of the blog post due to incorrect timezone.

Is there a way I can convert BST to MDT?

but it gets even more complex because some months of the year in England we use GMT (GMT+0) instead of BST (GMT+1) ... is there anyway to work out which timezone is being used in England at the time of year and do a conversion or am I just way overcomplicating this whole matter?

The following solution works perfectly:

$oldDate = date('l F j Y H:i:s', $link['date']);
$date = new DateTime($oldDate, new DateTimeZone('Europe/London'));
$date->setTimezone(new DateTimeZone('UTC'));
echo $date->format('r');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM