Solved

Java Date Expiration

Posted on 2011-09-23
3
295 Views
Last Modified: 2012-06-22
Hello,

I was wondering what is the best way to see if a Date is over 24 hours old in Java.  
0
Comment
Question by:cgray1223
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 36590021
Something like
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, -1);
boolean over24HoursOld = dateBeingTested.before(c.getTime());

Open in new window

0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 250 total points
ID: 36590035

Date d;


Date d1 = new java.util.Date();

if(d1.getTime()-d.getTime() > 24L*3600L*1000L)System.out.println("it is older");
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36711820
:)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spring maven example issues 3 38
Running JavaFX on the Raspberry Pi 27 128
junit example issue 2 24
IBM TS2900 (3572) Tape Autoloader Java? 12 57
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question