使用 PHP 将数据库时间转换为 BST
因此,我已经尝试了各种组合来从我的数据库(使用WordPress)中获得约会,以在英国夏季显示,我无法完成任何工作。
是否有任何简单的解决方案可以采用日期字符串,并确保在英国夏季距离UTC时间一个小时?
$classJson = $class->info;
$classJsonAsArray = json_decode($classJson, TRUE);
$classStartDate = strtotime($class->periodStart);
$classStartTime = date('H:i',$classStartDate);
因此,当前$ class-> ocerdstart返回:2022-04-06 08:30:00
该活动的时间应该是上午
9.30它显示为上午8.30。
So I've trying all sorts of combinations to get a date from my database (using Wordpress) to display in British Summer Time and I cannot get anything to work.
Is there any simple solution that can take the date string and make sure that in Summer Time in the UK it's an hour on from UTC time?
$classJson = $class->info;
$classJsonAsArray = json_decode($classJson, TRUE);
$classStartDate = strtotime($class->periodStart);
$classStartTime = date('H:i',$classStartDate);
So currently $class->periodStart returns: 2022-04-06 08:30:00
The time of that event should be 9.30am
All I need it to do is display the correct time, as at the moment, on the front end it displays as 8.30am.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DateTime
很好地处理时区。DateTime
handles timezones quite well.像接受的答案一样使用日期时间和时区是更好的方法。
但如果时区附加到日期字符串,它也适用于 strtotime。然后 Date 返回时间戳的本地时间。
Working with DateTime and timezones like in the accepted answer is the better way.
But it also works with strtotime if the timezone is appended to the date string. Date then returns the local time for a timestamp.