Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Analizing Dates for Calculation

 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the following to see if a datetime is before current datetime but it seems that my checkdate is only reading the date porition

Console output

CheckD: 2010-05-24 08:09:08.655872
CT: Mon May 24 12:42:24 CDT 2010
KT: Mon May 24 13:42:24 CDT 2010
LF: 0

 
Sue Temple
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a printline to your catch block and you will see what went wrong -

Replace:


with:
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A ParseException happens but you don't notice, because you are swallowing the exception in lines 12-14.

Note that the format you specified to parse the date "dd/MM/yyyy HH:mm:ss" doesn't match what you put in: "2010-05-24 08:09:08.655872"

Don't ever swallow exceptions like that, at least print an error message.
 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sue Temple wrote:Add a printline to your catch block and you will see what went wrong -

Replace:


with:


Thanks, works great now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic