tags:

views:

44

answers:

4

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
A: 

.

echo date('r');
putenv('TZ=PST');
echo date('r');  
Sarfraz
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
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