How to change timezone in PHP to an existing timestamp?

Code for 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 FY", strtotime($profile[last_activity_date_and_time])); ?> 

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

When displayed, displayed until January 18, 2010 - 02:34 pm

But is there a way to change the time zone on which it is displayed?

+6
date timezone php datetime time
source share
2 answers

Not sure if this is what you are 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); 
+18
source share

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

 date_default_timezone_set('Europe/London'); 
0
source share

All Articles