/    Sign up×
Community /Pin to ProfileBookmark

Calculate time difference in hours

Hi there to you all!

I’m new to java, used to programming in SQL, VB, HTML and Flash only.

However, I have a problem that could be best solved with Java. Can anyone help me please?

I need to calculate a time difference between the exact current date and 05/28/2004 10:00:00 AM in hours.

After obtaining these hours (eg 52 at the very moment), I need to divide them by 100 and add them to 35. The current value would be 35,52 at the moment.

Then the number should be output in a simple textbox.

I found some birthday calculators, but I seem to not quite get the knack.

This is for a timer on a homepage … of course I would thank the person who could provide me with the source code for this!

I hope someone can help me!

Greetings

Rhadan, RJ

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@PittimannMay 30.2004 — Hi!

Something like this:[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function getDiff(){
var oldDate=Date.parse(new Date(2004,4,28,10,0,0));
var newDate=Date.parse(new Date());
var diff=newDate-oldDate;
diff=diff/86400000*24;
diff=diff/100+35;
diff=diff.toFixed(2);
document.forms[0].timeDiff.value=diff;
}
//-->
</script>
</head>
<body onload="getDiff()">
<form>
<input name="timeDiff">
</form>
</body>
</html>[/code]
Cheers - Pit
Copy linkTweet thisAlerts:
@rhadanauthorMay 30.2004 — Thank you, seems to work very well!

I take it if it exceeds 35,99 it will switch to 36?

Any special credits I can give you or just your name??

Thanks again!

Rhadan, rj
Copy linkTweet thisAlerts:
@PittimannMay 30.2004 — Hi!

You're welcome!I take it if it exceeds 35,99 it will switch to 36?[/QUOTE]Of course, but only if the document is reloaded; it will show what you want anytime a user enters the page with the code in it.

No need to put some credit, I am glad to help and that's enough. I have observed, that you repeatedly use a comma as a decimal separator (which in Germany - where I live - is the case as well). Do you want the "." to be replaced with a ","?

Cheers - Pit
Copy linkTweet thisAlerts:
@rhadanauthorMay 30.2004 — Hallo noch mal!

Danke, aber das ist nicht wirklich notwendig.

Ich werde die Seite bald hochladen, dann werde ich den Link hier reinposten.

Danke noch mal!

lg

Rhadanm, rj
Copy linkTweet thisAlerts:
@PittimannMay 30.2004 — Hi!

Ist aber kinderleicht: diese beiden Zeilen

diff=diff.toString();

diff=diff.replace('.',',');

gehören dazu vor diese:

document.forms[0].timeDiff.value=diff;

Nochmals: keine Ursache!

Ahoi - Pit
Copy linkTweet thisAlerts:
@rhadanauthorMay 30.2004 — Hallo wieder!

Ich hab die beiden Zeilen doch noch eingefügt ... wenn's schon so einfach geht ...

Die Homepage ist zu finden unter: http://members.chello.at/rhadan/pirates.htm

Der Timer unter "Anmeldung"!

lG

Rhadan, rj
Copy linkTweet thisAlerts:
@PittimannMay 30.2004 — Hi!

Nun versteh' ich :p - hatte mich schon gewundert, was das soll.

Tschüß 'n cheers - Pit
×

Success!

Help @rhadan 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.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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