472,364 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

2 different time zones

I have 4 sites sharing an account on a server that is in the US Eastern
time zone. 3 of those sites are for businesses/persons who live in the
same time zone, but one is for a restaurant in the US Pacific time zone.

For that site, I want to generate content via a script depending on the
local Pacific time and day of week. The content will change at the same
time every day: one page before 5:00am local time, a different page from
5am until 10pm, then back to the first page after 10pm. The script
should also generate appropriate last modified and expires headers. It'd
be nice if this script were portable, in case I change hosting companies
and wind up with a host in European time, or US central time, or what
have you.

At the moment, my script gets the local time of the server (US ET),
converts it to UT with date("Z"), then converts it again to Pacific time:

$utTimeStamp = time() - date("Z");
$daylightSavingsTime = date("I");
$PT = $utTimeStamp - (8*3600) + ($daylightSavingsTime*3600);

That's fine for the current time, but trying to work out expires times
seems rather complicated, and I'm having a hard time getting everything
to work. Is there an easier way to accomplish my tasks? Should I give up
some portability and simply convert from one local time to another?

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #1
4 3754
*** Brian escribió/wrote (Wed, 29 Sep 2004 20:54:26 GMT):
I have 4 sites sharing an account on a server that is in the US Eastern
time zone. 3 of those sites are for businesses/persons who live in the
same time zone, but one is for a restaurant in the US Pacific time zone.


I believe this task is usually solved using GMT internally for all dates
and doing conversion to client time zone when printing. You have some
functions to work with Greenwich time:

gmdate - Format a GMT/UTC date/time
gmmktime - Get UNIX timestamp for a GMT date
gmstrftime - Format a GMT/UTC time/date according to locale settings
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #2
Brian wrote:
[snip]
$utTimeStamp = time() - date("Z");
$daylightSavingsTime = date("I");
$PT = $utTimeStamp - (8*3600) + ($daylightSavingsTime*3600);

That's fine for the current time, but trying to work out expires times
seems rather complicated, and I'm having a hard time getting everything
to work. Is there an easier way to accomplish my tasks? Should I give up
some portability and simply convert from one local time to another?


Use gmdate() for expiry headers

// expire in half an hour (wherever you are)
header('Expires: ' . gmdate('r', time()+1800));
--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #3
Pedro Graca wrote:
Brian wrote: [snip]
trying to work out expires times seems rather complicated


Use gmdate() for expiry headers

// expire in half an hour (wherever you are)
header('Expires: ' . gmdate('r', time()+1800));


That would work if the document didn't have a hard expires time, though
in that case, a cache-control header would be more straight-forward:
header('Cache-Control: max-age=1800');

But the document expires according to the time of day US Pacific time.
The page will show the dinner special. Since the kitchen closes at 10:00
pm each night, the page showing that day's special expires at 10:00pm or
22:00 each day. If someone views the page at 21:59, it is fresh for only
1 minute. If they view it at 06:00 (6am), it is fresh for 14 hours.

I need to get the time of day in Seattle using the server's clock, which
is set to US eastern time. Then I need to create a date formatted for an
http header, based on the current date, but using a hard time. For
example, if I were to view the page at the time I write this article --
Thursday, 30 September 2004 at 12:59pm US PDT -- the page should show
Thursday's dinner special, and the expires header should be

Expires: Thu, 30 Sep 2004 22:00:00 GMT

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #4
Alvaro G. Vicario wrote:
*** Brian escribió/wrote (Wed, 29 Sep 2004 20:54:26 GMT):
I have 4 sites sharing an account on a server that is in the US
Eastern time zone. 3 of those sites are for businesses/persons who
live in the same time zone, but one is for a restaurant in the US
Pacific time zone.

I believe this task is usually solved using GMT internally for all
dates and doing conversion to client time zone when printing. You
have some functions to work with Greenwich time:

gmdate - Format a GMT/UTC date/time
gmmktime - Get UNIX timestamp for a GMT date
gmstrftime - Format a GMT/UTC time/date according to locale settings


The documentation for gm* date functions on php.net is not terribly
clear to me. gmmktime gets a unix timestampe for a GMT date, but I need
to determine what to do based on a local time zone, and account for
daylight savings. That's complicated by the fact that the server's
localtime is not the restaurant's local time. I need to set an expires
header based on the local time of the restaurant, but the time must be
expressed in GMT. 2 examples:

1. if it's between 05:00 and 22:00 US PT, the page should insert that
day's dinner special, and the expires header should be set to 22:00
local time. Since US PT is currently in daylight savings (GMT -0700),
that means that for today, Thursday 30 September 2004, it should be

Expires: Fri, 01 Oct 2004 05:00:00 GMT
2. if it's after 22:00, the page should not show the special, and the
page should expire the next day at 05:00. The expires header should thus be

Expires: Fri, 01 Oct 2004 12:00:00 GMT

What I find difficult is doing date calculations, while at the same time
having to hardcode the time. For example 2, I'm trying to determine the
current date, change it to tomorrow, and create a unix time stamp based
on tomorrow at 05:00.

I started this thread to see if I'm making this too complicated -- I
suspect that I am -- and determine if there's an easier way to work in
US PT or GMT.

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone...
11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
6
by: Rebecca Smith | last post by:
Today’s question involves two time text boxes each set to a different time zone. Initially txtCurrentTime will be set to Pacific Time or system time. This will change with system time as we travel...
0
by: Sabotage | last post by:
Hi all, I am looking to download time zones list for my multilingual software. I found time zones list in english here:...
13
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to...
7
by: Dick | last post by:
I have a long list of events. I know where each event took place (globally) and when (using the event’s local time). I want to do some comparisons between these date/times. I thought I would...
6
by: dredge | last post by:
Hi, the server that hosts my PHP pages has its clock set to Greenwich Mean Time (GMT timezone 0). I need for my PHP scripts to have access to my local time which is Central Standard Time in the...
1
by: scan87 | last post by:
Can someone please, please help me in finding the slotuion of the following problem: The cost of one-day travel cards for adult customers on the metro system is based on which zones they cover and...
1
by: AnshuGupta | last post by:
Hello, I have an application coded in .Net c# that has to display the list of available time zones. This application supports both english and french language. Is it possible to display the list...
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.