1

Is there a way to get specific timezone without changing the default timezone? I tried to use this code to get the timezone but when I revert back its not different output.

echo '<br />'.date('Y-m-d H:i:s') . '<br />';
date_default_timezone_set('Australia/Melbourne'); 
echo '<br />' . date('Y-m-d H:i:s');
date_default_timezone_set('America/Chicago'); 
echo '<br />' . date('Y-m-d H:i:s');

Output: 2013-08-15 03:24:48 2013-08-15 13:24:48 2013-08-14 22:24:48

as the output the last row added a time.

Kye
  • 5,919
  • 10
  • 49
  • 84

2 Answers2

2

According to strtotime and datetime formats, you can do something like:

echo date("Y-m-d H:i:s",strtotime(date("H:i:s")." America/Chicago"));

Or even better:

echo date("Y-m-d H:i:s",strtotime("now America/Chicago"));
0

✓ The following code will output:


Australia/Melbourne time - 2013-08-15 13:48:57

America/New_York - 2013-08-14 23:48:57

<?php

echo "Australia/Melbourne time - ";
$now = new DateTime(null, new DateTimeZone('Australia/Melbourne'));
echo $now->format('Y-m-d H:i:s');

echo "<br>";

echo "America/New_York - ";

$now = new DateTime(null, new DateTimeZone('America/New_York'));
echo $now->format('Y-m-d H:i:s');

?>
Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141