Compare two date and time objects

Put your problem here if it does not fit any of the other categories.

Compare two date and time objects

Postby erbedo » Fri Mar 14, 2008 10:41 pm

Hi
I got from an XML file a list of string in this format:
yyyyMMddhhmmss
I need to compare this values to the current time.
I tried to do:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                                
  2.  
  3.                                 DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
  4.  
  5.                                 Date date = new Date();
  6.  
  7.                                 String timeNow = dateFormat.format(date);
  8.  
  9.                                
  10.  
  11.                                 // start is a long variable, containing a number in the format above
  12.  
  13.                                 if ( start >= timeNow ) {
  14.  
  15.                                      // doSomething()
  16.  
  17.                                 }
  18.  
  19.                         }
  20.  
  21.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


But i got NullPointerException :(

Any hint?
erbedo
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Mar 13, 2008 9:39 pm

Top

Postby erbedo » Mon Mar 17, 2008 1:32 am

Update:

I found that such a number, like the above, is too big for a long variable. Actually, I've solved splitting the string in two part, date and time, and comparing each other to the current date and time, but... I hope there's another, appropriate method, but I wasn't able to find it out. Anybody knows it?

TIA
Proudly supporting Android :)
erbedo
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Mar 13, 2008 9:39 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests