What is easiest way to display the current time in PST (West Coast) time using PHP?
+3
A:
Well, the easiest might be:
default_timezone_set('America/Los_Angeles');
echo date('Y-m-d');
Take a look at supported timezones to find one suitable for your needs.
Tatu Ulmanen
2010-06-15 18:59:12
A:
To convert a date/time between timezones:
include ("Date.php");
$d = new Date("2010-06-21 10:59:27"); // initialize object
$d->setTZByID("GMT"); // set local time zone
$d->convertTZByID("PST"); // convert to foreign time zone
echo $d->format("%A, %d %B %Y %T"); // retrieve converted date/time
Jeriko
2010-06-15 19:00:54
A:
Let's try a solution that uses PHP's modern date handling. This example requires PHP 5.2 or better.
// Right now it's about four minutes before 1 PM, PST.
$pst = new DateTimeZone('America/Los_Angeles');
$three_hours_ago = new DateTime('-3 hours', $pst); // first argument uses strtotime parsing
echo $three_hours_ago->format('Y-m-d H:i:s'); // "2010-06-15 09:56:36"
Charles
2010-06-15 19:57:44