rik408
02-13-2003, 08:26 PM
Hello,
I was wondering if someone could give me a hand with this. I believe
I have obtained the correct UTC (GMT, Greenwich) time, but I am
having some difficulty getting it to convert to Hong Kong and New
York times.
Hong Kond is + 8 hours, and New York is - 5 hours,
Anyway, here is the code. I have included the HTML to make copy-n-
paste easier.
--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Untitled Document</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-
1">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var time = new Date();
var hour = time.getUTCHours();
var minute = time.getUTCMinutes();
var day = time.getUTCDay();
var wd;
var apm = "am";
var dn = new Array
("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sa
turday")
var london = hour; // London Time = CMT Time: UTC -0 Hours
var hkt = hour+ 8; //Hong Kong Time = UTC +8 Hours
var nyt = hour - 5; //New York Time = UTC -5 Hours
wd = dn[day];
day += 10;
if (hour > 11) apm = "pm";
if (minute <= 9) minute = "0" + minute;
if (hour > 12) hour = hour - 12;
if (hour == 0) hour = 12;
if (day == 1) day += "st"
if (day == 2) day += "nd"
if (day == 3) day += "rd"
if (day >= 4 && day <= 20) day += "th"
if (day == 21) day += "st"
if (day == 22) day += "nd"
if (day == 23) day += "rd"
if (day >= 24 && day <= 30) day += "th"
if (day == 31) day += "st"
var CMT;
CMT = hour + ":" + minute + " " + apm + " ¤ " + wd + ", " + day;
var CMT2 = CMT = hour + minute +":" + " " + apm + "
<BIG>•</BIG> " + day + ", " ;
var CMT3 = hour + ":" + minute + " " + apm + " <BIG>:</BIG> " + wd
+ " " + "the " +day;
var hk = hkt + ":" + minute + " " + apm + " <BIG>:</BIG> " + wd
+ " " + "the " +day;
var ny = nyt + ":" + minute + " " + apm + " <BIG>:</BIG> " + wd
+ " " + "the " +day;
document.write("London: " +CMT3);
document.write("<BR>");
document.write("Hong Kong: " +hk);
document.write("<BR>");
document.write("New York: " +ny);
//document.theClock.theTime.value =ny; //write to text area
// -->
</SCRIPT>
<BR>
<BR>
<form name="theClock">
<input type=text name="theTime" size=8>
</form>
</BODY>
</HTML>
--
Here are the results I obtained:
London: 7:37 pm : Thursday the 14th
Hong Kong: 27:37 pm : Thursday the 14th
New York: 14:37 pm : Thursday the 14th
I believe London is ok, but HK should be "Friday" by now, and there
is no such time as "27:37" (even on a 24-hour clock!). I wanted all
in AM/PM format. As you can see, New Yourk's time reverted back to a
24 hour clock as well.
Also, I wanted all 3 results to write to a text box, but again, I am
having problems.
If anyone could assist, they would have my appreciation.
Rick
I was wondering if someone could give me a hand with this. I believe
I have obtained the correct UTC (GMT, Greenwich) time, but I am
having some difficulty getting it to convert to Hong Kong and New
York times.
Hong Kond is + 8 hours, and New York is - 5 hours,
Anyway, here is the code. I have included the HTML to make copy-n-
paste easier.
--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Untitled Document</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-
1">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var time = new Date();
var hour = time.getUTCHours();
var minute = time.getUTCMinutes();
var day = time.getUTCDay();
var wd;
var apm = "am";
var dn = new Array
("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sa
turday")
var london = hour; // London Time = CMT Time: UTC -0 Hours
var hkt = hour+ 8; //Hong Kong Time = UTC +8 Hours
var nyt = hour - 5; //New York Time = UTC -5 Hours
wd = dn[day];
day += 10;
if (hour > 11) apm = "pm";
if (minute <= 9) minute = "0" + minute;
if (hour > 12) hour = hour - 12;
if (hour == 0) hour = 12;
if (day == 1) day += "st"
if (day == 2) day += "nd"
if (day == 3) day += "rd"
if (day >= 4 && day <= 20) day += "th"
if (day == 21) day += "st"
if (day == 22) day += "nd"
if (day == 23) day += "rd"
if (day >= 24 && day <= 30) day += "th"
if (day == 31) day += "st"
var CMT;
CMT = hour + ":" + minute + " " + apm + " ¤ " + wd + ", " + day;
var CMT2 = CMT = hour + minute +":" + " " + apm + "
<BIG>•</BIG> " + day + ", " ;
var CMT3 = hour + ":" + minute + " " + apm + " <BIG>:</BIG> " + wd
+ " " + "the " +day;
var hk = hkt + ":" + minute + " " + apm + " <BIG>:</BIG> " + wd
+ " " + "the " +day;
var ny = nyt + ":" + minute + " " + apm + " <BIG>:</BIG> " + wd
+ " " + "the " +day;
document.write("London: " +CMT3);
document.write("<BR>");
document.write("Hong Kong: " +hk);
document.write("<BR>");
document.write("New York: " +ny);
//document.theClock.theTime.value =ny; //write to text area
// -->
</SCRIPT>
<BR>
<BR>
<form name="theClock">
<input type=text name="theTime" size=8>
</form>
</BODY>
</HTML>
--
Here are the results I obtained:
London: 7:37 pm : Thursday the 14th
Hong Kong: 27:37 pm : Thursday the 14th
New York: 14:37 pm : Thursday the 14th
I believe London is ok, but HK should be "Friday" by now, and there
is no such time as "27:37" (even on a 24-hour clock!). I wanted all
in AM/PM format. As you can see, New Yourk's time reverted back to a
24 hour clock as well.
Also, I wanted all 3 results to write to a text box, but again, I am
having problems.
If anyone could assist, they would have my appreciation.
Rick