• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date calculation  RSS feed

 
Pam Theod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a situation where I need to find difference between 2 datetimes in minutes. If the difference between the 2 datetimes is more than 20 minutes I will have to run a process.

I always need to compare current datetime with the datetime I get from the user.

for ex:
Date1 - currenttime
Date2 - user input ( this will always be past datetime)

Find difference between Date1 and Date2 in minutes.

Any insight on this is greatly appreciated.

Thanks in advance.

P P
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could construct 2 Date objects, and call getTime() on each. getTime returns a long that represents the number of milliseconds since January 1, 1970. Then you can compute the difference.
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Please change your name to match the naming policy.

You know that the Calendar classes count how many millseconds have passed since 1.00am 1st January 1970 (we had Summer Time = Daylight Saving Time all the year round that year, so midnight GMT fell at 1.00am)?
So if you subtract the time given from a GregorianCalendar object created "now," you get the time difference. Divide by 1200000, or
 
Pam Theod
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone for the input.

I got this to work.

Btw I updated my profile
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!