views:

125

answers:

3

The code for the date and time function:

function date_and_time($format,$timestamp) {

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

}

And then the code to display it:

    <?php

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

    ?>

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

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

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

A: 

Try this:

date_default_timezone_set('America/New_York');

You can change the timezone as appropriate: list of supported timezones

John Conde
Yeah but that only seems to work with new timestamps, not existing ones
Ryan
A: 

You can use the this function to set default time zone:

date_default_timezone_set('Europe/London');
Sarfraz
Yeah but that only seems to work with new timestamps, not existing ones
Ryan
+1  A: 

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);
Gordon
Other answers address adjusting the Timezone for new dates, however yours is the only one that addresses adjusting the Timezone for an existing date.
Jordan S. Jones