Closed Thread Icon

Topic awaiting preservation: Pls help me with Javascript date (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=8753" title="Pages that link to Topic awaiting preservation: Pls help me with Javascript date (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Pls help me with Javascript date <span class="small">(Page 1 of 1)</span>\

 
Pimms One
Bipolar (III) Inmate

From: Australia
Insane since: Jun 2003

posted posted 07-14-2003 06:05

Hi!

I will need to create a date to be viewed by users in two locatoin. i.e.

Sydney Wed, 12 July 2003
San Francisco Tue, 11 July 2003

If Sydney is GMT +10 and San Francisco is GMT -7, how can the javascript (which I use the Date() function) to know what day it is in and calculate the date from another location?

I am stuck after many attempts. Can you cast some light into this problem? Thank you.

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 07-14-2003 06:11

Hi, mate. How are ya?
Hmm.......I want to know how to do it as well.
Well, I bought a JS book yesterday.
I will try to find out how tonight.
If I find something cool, I will let you know.
Cya.

Ps. I know a lot of great Aussies. I am a kiwi ( trying to be tough) now.
Do you know Timaru? I am there.

Hiroki Kozai

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-14-2003 10:00

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!-- ;

// Written by mr.maX, http://www.max.co.yu/

function maxGetDate(Offset)
{
Today = new Date();
TimeZoneOffset = Today.getTimezoneOffset()*60000;
GMT = new Date(Today.getTime()+TimeZoneOffset);
return new Date(GMT.getTime()+Offset*3600000);
}

// IMPORTANT! Note that maxGetDate() function doesn't handle daylight savings time,
// so it's up to you to insure that time zone offset from GMT is correct!
// For example Belgrade is located at GMT+1, but since currently DST is active,
// offset needs to be increased by one, and that's why you see 2 instead of 1 below...
Belgrade = maxGetDate(2);
document.write('<B>Belgrade:</B> ' + Belgrade.toLocaleString() + '<BR>');

Sydney = maxGetDate(10);
SanFrancisco = maxGetDate(-7);
document.write('<B>Sydney:</B> ' + Sydney.toLocaleString() + '<BR>');
document.write('<B>San Francisco:</B> ' + SanFrancisco.toLocaleString());

// -->
</SCRIPT>

Enjoy!


Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 07-15-2003 02:32

Hi, mate. I found one in my book.

Here is script for you:

code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>Time Zones</TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers

dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")

function showTheHours(theHour) {
if (theHour == 0) {
return (12)
}
if (theHour < 13) {
return (theHour)
}
return (theHour-12)
}

function showZeroFilled(inValue) {
if (inValue > 9) {
return ":" + inValue
}
return ":0" + inValue
}

function showAmPm(thatTime) {
if (thatTime < 12) {
return (" AM ")
}
return (" PM ")
}

function showTheTime(tzOffset) {
thatTZ = new Date
dateStr = thatTZ.toGMTString()
dateStr = dateStr.substr(0,dateStr.length - 3)
thatTZ.setTime(Date.parse(dateStr))
thatTZ.setHours(thatTZ.getHours() + tzOffset)

return showTheHours(thatTZ.getHours()) + showZeroFilled(thatTZ.getMinutes()) + showAmPm(thatTZ.getHours()) + dayName[thatTZ.getDay()]
}

// End hiding script from old browsers -->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="WHITE">
<H3>Our office hours are 9:00 am to 5:00 pm, Monday through Friday, at each of our locations.<BR><BR>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers

document.write("London: " + showTheTime(0))
document.write("<BR>New York: " + showTheTime(-5))
document.write("<BR>San Francisco: " + showTheTime(-8))

// End hiding script from old browsers -->
</SCRIPT>
</H3>
</BODY>
</HTML>



Hope it helps.
Cheers.

Hiroki Kozai

Pimms One
Bipolar (III) Inmate

From: Australia
Insane since: Jun 2003

posted posted 07-16-2003 06:11

Thank you guys. It works now. Thanks again.

« BackwardsOnwards »

Show Forum Drop Down Menu