Jump to content

[SOLVED] server time adjustment


Grant Holmes

Recommended Posts

I have a processing form reporting the time when a record is inserted. This field is never changed. However, our server (Yahoo) is in London. My client is in CA. I'd like to post a time relevant to LA.

 

In my page I do:

 

$time=date("Y-m-d H:i:s");

 

Is there a way to subtract the 9 hour difference? H-9??

Link to comment
https://forums.phpfreaks.com/topic/89941-solved-server-time-adjustment/
Share on other sites

Timezone --- --- 
e Timezone identifier (added in PHP 5.1.0) Examples: UTC, GMT, Atlantic/Azores 
I (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. 
O Difference to Greenwich time (GMT) in hours Example: +0200 
P Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) Example: +02:00 
T Timezone abbreviation Examples: EST, MDT ... 
Z Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400 

 

http://ca3.php.net/manual/en/function.date.php

 

Try that

If you want the date() function to return dates/times in CA timezone, use this at the beginning of your script:

date_ default_ timezone_ set('America/Los_Angeles');

 

As far as making a script show dates auto-adjusted to the client's timezone, it's a little trickier. The only way to get the client's timezone is with javascript.

Thanks for the help gang.

 

phpSensei, I read that page, but I'm noob to PHP and have no idea what to edit/add/whatever.

 

rhodesa, (see above on being a newbie)... I put that above my code within the php like this:

date_ default_ timezone_ set('America/Los_Angeles');
$time=date("Y-m-d H:i:s");

but then the page failed to display. HELP!?

sorry...i copied/pasted the function name and it ended up with spaces in there:

 

date_default_timezone_set('America/Los_Angeles');
$time=date("Y-m-d H:i:s T");

 

I also added a T to your date format so you could see what timezone it was using

phpSensei, your solution returns zeros: "0000-00-00 00:00:00" and I don't see where you're assigning the value to: $time

 

rhodesa, yours still returns a blank page.

 

putenv('TZ=$timezone');

 

 

try

 

<?php
      $timezone = "America/Los_Angeles";

putenv('TZ=$timezone');
echo date('Y-m-d h:i:s');
?>

 

returns: 2008-02-07 03:31:12

Okay kids, it's getting deep.

 

Yes, that worked. I'm not sure why. I'm SURE I don't care!!

 

Thanks a BUNCH!!!!

 

hey, if you're bored... I'm stuck on this one: More Header Fun

 

Not sure why it worked? lol what do you mean? I can explain the code if you want...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.