473,903 Members | 3,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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");
$daylightSaving sTime = date("I");
$PT = $utTimeStamp - (8*3600) + ($daylightSavin gsTime*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 3866
*** 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");
$daylightSaving sTime = date("I");
$PT = $utTimeStamp - (8*3600) + ($daylightSavin gsTime*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
12967
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 here put me straight on the following: I had a look at the time() function came across this: "To clarify, it seems this function returns the time of the computer's clock and does not do any timezone adjustments to return GMT, so you are...
11
4693
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 having a heck of a time doing so. I have created a form where I use drop downs do specify year, month, date, hour, minute and seconds. When the form is loaded, the dropdowns have to display the proper values for the current time zone type. This
6
2861
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 across the country. txtRaceTime will always be set to Central Time regardless of where we are in the US. At first I tried ‘Now() – “xx:xx:xx” but that produced an error. Anyway as we approach the east coast the ‘minus’ would need to be a...
0
1748
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wpossetup/htm/microsofttimezoneindexvalues.asp Could anybody advice where could I download time zones list in french, italian, etc? I googled a lot but without any success. Thanks a lot.
13
16186
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 local time from UTC function formatToLocalTimeDate(inDate) { var today = new Date(); var inDateMod = new Date(inDate);
7
2687
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 convert them all to UTC and thus get them all on a common time-line. But I can’t see how to do this. I can use TimeZone.CurrentTimeZone to get the current TimeZone object and use its ToUniversalTime method to convert dates that occurred in the...
6
5171
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 U.S. (CST timezone -6). Note: daylight savings time _is_ observed in my state. I have looked all over a PHP algorithm that would convert GMT to CST but have so far not been successful. Does anyone have such an algorithm lying around that they could...
1
1965
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 is summarised in the following table: Zone Cost 1 1.70 1 & 2 3.70 1, 2 & 3 4.70 1, 2, 3 & 4 6.00 1,...
1
2484
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 of time zones in different languages (english or french)? The Windows OS is in english. Thanks
10
4042
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 problem. This function does not recognize time zones. How to adjust date to user's time zone? Is converting to timestamp() and then to format readable to visitors the one and only solution (e.g. strtotime() + date() OR DateTime object)? Perhaps,...
0
10875
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7206
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6093
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4727
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4308
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3324
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.