如何更改现有时间戳的PHP中的时区? [英] How do you change the timezone in PHP for an existing timestamp?

查看:114
本文介绍了如何更改现有时间戳的PHP中的时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

日期和时间函数的代码:

The code for the date and time function:

function date_and_time($format,$timestamp) {

$date_and_time = date($format,$timestamp);
return $date_and_time;

}

然后显示代码:

    <?php

        echo date_and_time("dS F Y", strtotime($profile[last_activity_date_and_time]));

    ?>

$ profile [last_activity_date_and_time]的值为2010-01-18 14:34:04

The value of $profile[last_activity_date_and_time] is 2010-01-18 14:34:04

显示时显示为2010年1月18日 - 02:34 pm

When displayed it shows up as 18th January 2010 - 02:34pm

但是,有没有办法改变时区显示在?

But, is there any way to change the timezone it is displayed in?

推荐答案

不知道这是你要找什么,但尝试 DateTime

Not sure if this what you're looking for, but try DateTime

date_default_timezone_set('Europe/London');

$datetime = new DateTime();
$datetime->setTimestamp($yourTimestamp);
echo $datetime->getTimezone()->getName();
echo $datetime->format(DATE_ATOM);

$la_time = new DateTimeZone('America/Los_Angeles');
$datetime->setTimezone($la_time);
echo $datetime->getTimezone()->getName();
echo $datetime->format(DATE_ATOM);

这篇关于如何更改现有时间戳的PHP中的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆