473,583 Members | 3,114 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 3851
*** 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
12889
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...
11
4634
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...
6
2843
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...
0
1728
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...
13
16143
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
2670
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...
6
5144
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...
1
1947
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 ...
1
2469
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
4009
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...
0
7827
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8184
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8328
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...
0
6581
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...
1
5701
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5375
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...
0
3820
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...
1
2334
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
0
1158
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...

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.