/    Sign up×
Community /Pin to ProfileBookmark

How do I get 1/2 hour on a clock?

Hello,
I have a world clock program that is set for hours, minutes, seconds.
The problem is that I need to have this clock adjust by 1/2 hour.
Here is the javascript line:

var afg =check24(((gmt + 4) > 24) ? ((gmt + 4) – 24) : (gmt + 4));
document.clock.afg.value = (IfZero(afg) + ending);

I know it is probablyu simple but I am just learning and sure could use some help

?
Thanks

waytoofast

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@waytoofastauthorNov 12.2004 — I might have not explained that right.?

I need the clock to adjust from 4 hours to 4 1/2 hours.

Thanks

waytoofast
Copy linkTweet thisAlerts:
@CharlesNov 12.2004 — Please describe in great detail just what it is that this clock does now and what you would like it to do.
Copy linkTweet thisAlerts:
@senshiNov 12.2004 — in its simplest of terms, using .5 to represent 30 minutes as a decimal system, if you use the new Date() method to create a time object. In this case you would add 30 for half an hour.
Copy linkTweet thisAlerts:
@JuuitchanNov 12.2004 — First, adjust the minutes by 30.

Then, check to see if the minutes are 60 or over. If they are, subtract 60 from the minutes and add 1 to the hours.

Next, take care of the hours.
Copy linkTweet thisAlerts:
@waytoofastauthorNov 12.2004 — The clock displays three time zones:

(All are based on GMT)

Local (adjusted to users computer time)

Second time (set to any time zone (plus or minus GMT))

Third time (set to any time zone (plus or minus GMT))

The local time and second time are fine as the time zones that I need is exactly 3+GMT.

But the third time zone is 4 1/2+GMT.

I have tried to adjust it by stating the time as 4.5, but that doesn't work.

is there a way to modify the script to reflect the half hour difference?

I hope I explained this weel enough, if not you could email me.

Thanks

waytofast
Copy linkTweet thisAlerts:
@CharlesNov 12.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title></title>

</head>

<body>

<script type="text/javascript">

<!--

Date.ONE_SECOND = 1000;

Date.ONE_MINUTE = Date.ONE_SECOND * 60;

Date.ONE_HOUR = Date.ONE_MINUTE *
60;

Date.prototype.toUTCOffset = function (offset) {return new Date(this.getTime() + this.getTimezoneOffset() * 60000 + offset * Date.ONE_HOUR)}

Date.prototype.toTimeString = function () {return [this.getHours() < 13 ? this.getHours() : this.getHours() - 12, this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes(), this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds()].join (':') + (this.getHours() < 13 ? ' AM' : ' PM')}

Date.tokyoTime = function () {return new Date().toUTCOffset(+9).toTimeString()}

Date.newDelhiTime = function () {return new Date().toUTCOffset(+5.5).toTimeString()}

Date.newYorkTime = function () {return new Date().toUTCOffset(-5).toTimeString()}

document.write('<dl>');

document.write ('<dt>Tokyo</dt><dd id="tokyoTime">', Date.tokyoTime (), '</dt>');

document.write ('<dt>New Delhi</dt><dd id="newDelhiTime">', Date.newDelhiTime (), '</dt>');

document.write ('<dt>Tokyo</dt><dd id="newYorkTime">', Date.newYorkTime (), '</dt>');

document.write ('</dl>');

if (document.getElementById) setInterval("document.getElementById('tokyoTime').firstChild.data = Date.tokyoTime (); document.getElementById('newDelhiTime').firstChild.data = Date.newDelhiTime (); document.getElementById('newYorkTime').firstChild.data = Date.newYorkTime ()", 0.2 * Date.ONE_SECOND);

// -->

</script>

</body>

</html>[/font]
Copy linkTweet thisAlerts:
@waytoofastauthorNov 12.2004 — Thank you so much Charles...you are the best!!!

waytoofast
Copy linkTweet thisAlerts:
@waytoofastauthorNov 12.2004 — Hi Charles,

One more question:

I am using Microsoft Front Page and the clock shows up on page when I use the 'review'tab'.

But it is invisible when I am on the 'normal page'.

Any clue why this happens?

Thanks again.

waytoofast?
Copy linkTweet thisAlerts:
@7studNov 12.2004 — I know it is probably simple but I am just learning and sure could use some help[/quote]

Maybe this will be easier to understand:
var date = new Date();
var hours = date.getUTCHours();
var minutes = date.getUTCMinutes();

//Display the hours and minutes in UTC time:
alert("Hours: " + hours +
"nMinutes: " + minutes);

//Get the number of milliseconds since Jan 1, 1970:
var millisecs = date.valueOf();

//Convert 4.5 hours to milliseconds:
//4.5 hours * 60 minutes/hr * 60 secs/minute * 1000 milliseconds/sec
var offset = 4.5 * 60 * 60 * 1000;

//Create a new date using the 4.5 hour offset:
var offset_date=new Date(millisecs + offset);

var od_hours = offset_date.getUTCHours();
var od_minutes = offset_date.getUTCMinutes();

//Display the the UTC time offset by +4.5 hours:
alert("Hours: " + od_hours +
"nMinutes: " + od_minutes);
?
Copy linkTweet thisAlerts:
@JuuitchanNov 12.2004 — (this.getHours() < 13 ? ' AM' : ' PM')

That should be 12, not 13.

And:

document.write ('<dt>Tokyo</dt><dd id="newYorkTime">', Date.newYorkTime (), '</dt>');

Is that Tokyo time or New York time?


------

Oh my goodness. The problem, waytoofast, might very well be that... you're going way too fast. This function check24(): what exactly is it supposed to do? Do you have the code for it?

I shouldn't be here. I need a girlfriend. When I get one, I intend to spend more time with her and less on this bloody forum.
Copy linkTweet thisAlerts:
@JuuitchanNov 12.2004 — I haven't tested it, 7stud, but that looks like a beautiful script. Unfortunately, waytoofast probably has too little knowledge of JavaScript for him to use it as it is. I wish that he had showed us the entire script before asking for help.

I wonder how much waytoofast knows about functions?
Copy linkTweet thisAlerts:
@waytoofastauthorNov 12.2004 — I am a beginner in javascript but I do understand function (with the help of you people and my books).

Here is the entire script:

<html>

<head>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function GetTime() {

var dt = new Date();

var def = dt.getTimezoneOffset()/60;

var gmt = (dt.getHours() + def);

document.clock.local.value = (IfZero(dt.getHours()) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));

var ending = ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds());

var irq =check24(((gmt + 3) > 24) ? ((gmt + 3)- 24) : (gmt + 3));

document.clock.irq.value = (IfZero(irq) + ending);

var afg =check24(((gmt + 4) > 24) ? ((gmt + 4) - 24) : (gmt +4));

document.clock.afg.value = (IfZero(afg) + ending);

setTimeout("GetTime()", 1000);

}

function IfZero(num) {

return ((num <= 9) ? ("0" + num) : num);

}

function check24(hour) {

return (hour >= 24) ? hour - 24 : hour;

}

// End -->

</script>

<title>Local Time</title>

</HEAD><BODY onLoad="javascript:GetTime();">

<center>

<form name="clock">

<strong><font size="1">LOCAL</font> <input type="text" size="6" name="local"></strong>

<p>

<font size="1">

IRAQ</font> <input type="text" size="6" name="irq"><br>

<font size="1">

AFGHANISTAN</font> <input type="text" size="6" name="afg"><br>

</form>

</center>

<!-- Script Size: 5.96 KB -->

</body>

</html>

I have tried inserting the (gmt + 4.5) into the afg.value (doesn't work). I can't figure out how to make it show 4 1/2 hour time difference I need.

Charles gave me a great script for the same type of clock, but it won't show on my 'normal' tab (mircosoft front page) so that I can make changes to the position of the timeframes.

Thank you all so much for your help.....everytime I read something here I get a little better.

See, you can teach an old dog new tricks:p

waytoofast
Copy linkTweet thisAlerts:
@JuuitchanNov 12.2004 — Okay. It looks like you took a script from the book and modified it without thinking deeply about what you were doing. Think: what job was the check24() function supposed to do? Once you understand that, why did you write MORE code to do that job, rather than letting the check24() function take care of it?
×

Success!

Help @waytoofast spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...