Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

Time arithmetic

Thread view: 
Stevens - 02 May 2004 06:24 GMT
Dear all,

How can I subtract two dates formatted like '01/04/03 12:02' and '01/04/03
11:38' and find their difference in minutes.

Cheers!
Roedy Green - 02 May 2004 07:22 GMT
>How can I subtract two dates formatted like '01/04/03 12:02' and '01/04/03
>11:38' and find their difference in minutes.
see http://mindprod.com/jgloss/calendar.html

just subtract the timestamps in milliseconds and divide by 60*1000.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
javac - 03 May 2004 22:53 GMT
> >How can I subtract two dates formatted like '01/04/03 12:02' and '01/04/03
> >11:38' and find their difference in minutes.
>  see http://mindprod.com/jgloss/calendar.html
>
> just subtract the timestamps in milliseconds and divide by 60*1000.

is there some "default" time stamp with which all objects are stamped
when they're instantiated?

javac@mail.com
http://www.geocities.com/cjavacjava/
Roedy Green - 04 May 2004 03:36 GMT
>is there some "default" time stamp with which all objects are stamped
>when they're instantiated?

Date objects contain the time they were created. Ordinary objects to
not.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
javac - 04 May 2004 23:22 GMT
> >is there some "default" time stamp with which all objects are stamped
> >when they're instantiated?
>
> Date objects contain the time they were created. Ordinary objects to
> not.

how would i start a "start watch" to count the time (milliseconds?)
from instantiation, please?  for ordinary objects, of course.

thanks,

javac@mail.com
http://www.geocities.com/cjavacjava/
Roedy Green - 04 May 2004 23:41 GMT
>how would i start a "start watch" to count the time (milliseconds?)
>from instantiation, please?  for ordinary objects, of course.
see http://mindprod.com/jgloss/time.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
javac - 05 May 2004 23:45 GMT
> >how would i start a "start watch" to count the time (milliseconds?)
> >from instantiation, please?  for ordinary objects, of course.
>  see http://mindprod.com/jgloss/time.html

thanks Roedy,

i'm hesitant to use a date generated _by_ the system clock, since
system clocks aren't necesarilly (sp) accurate.  is there an
alternative sort of ready-made object with a "time" of zero that
simply counts up, or should I make my own?

thanks,

javac@mail.com
http://www.geocities.com/cjavacjava/
Roedy Green - 06 May 2004 00:10 GMT
>i'm hesitant to use a date generated _by_ the system clock, since
>system clocks aren't necesarilly (sp) accurate.  is there an
>alternative sort of ready-made object with a "time" of zero that
>simply counts up, or should I make my own?

See http://mindprod.com/jgloss/setclock.html

and http://mindprod.com/jgloss/ntp.html
if you want very precise time.

If all you want is relative time, the system clock is fine, even if it
is inaccurate.

If all you want is a sequence number for objects, use static seq++
which will be faster by far than the clock.

CPUS have additional clocks besides the ticker.  To get at them you
would have to write JNI.

Perhaps if I knew what you were trying to accomplish I could direct
you better.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
javac - 06 May 2004 23:19 GMT
[..]
> If all you want is relative time, the system clock is fine, even if it
> is inaccurate.
>
> If all you want is a sequence number for objects, use static seq++
> which will be faster by far than the clock.
[..]

> Perhaps if I knew what you were trying to accomplish I could direct
> you better.

relative time is all i want.  life forms are born and die, each life
form'll have a life span (in miliseconds, presumably).  when their age
>= life span, or for other reason, then that life form'll die.

i don't like the idea of a system clock because i might be serializing
the life forms for storage, and that'd involve more arithmetic than a
simple timer that only counts "up" while the life form exists -- like
a stopwatch.

thanks,

javac@mail.com
http://www.geocities.com/cjavacjava/
Roedy Green - 07 May 2004 00:30 GMT
>relative time is all i want.

For you own objects you can just use a sequence number you increment
any time you allocate something.  To make it easier, you might have
private static int sequence = 0; per class.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
javac - 05 May 2004 23:45 GMT
> >how would i start a "start watch" to count the time (milliseconds?)
> >from instantiation, please?  for ordinary objects, of course.
>  see http://mindprod.com/jgloss/time.html

thanks Roedy,

i'm hesitant to use a date generated _by_ the system clock, since
system clocks aren't necesarilly (sp) accurate.  is there an
alternative sort of ready-made object with a "time" of zero that
simply counts up, or should I make my own?

thanks,

javac@mail.com
http://www.geocities.com/cjavacjava/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.