• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Compare current Date with given Date Java

 
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My date-time formatter is , "yyyy-MM-DD"


I want to check the date is later than today's date or not. I checked it using this validation.


But every time this returns false when the given date is later or not. Can anyone help with this me, please?
 
Saloon Keeper
Posts: 11054
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
 
Carey Brown
Saloon Keeper
Posts: 11054
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the newer LocalDate class.
 
Saloon Keeper
Posts: 28654
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java, a Date isn't just year/month/day. It's also time. When they were setting off midnight fireworks in Canberra on Jan 1 2021, I hadn't even eaten lunch on New Year's Eve. Internally, a java.util.Data is simply the number of milliseconds since midnight, Jan 1, 1970 in the Greenwich ((UTC) time zone. This is why the month/day/year constructor for java.util.Date has been deprecated for nearly 2 decades.

The no-argument Date constructor constructs based on the UTC date, which it determines from system locale settings.

There is no actual concept of month, day, or year in java.util.Date. Getting a date in and out - and in what format: MM/dd/yy, yyyy-mm-dd or whatever and what calendar (western, Judaic, hegira, or even Japanese Imperial) is the province of the various Java calendar classes, as augmented by "recent" time/date services (they're not as recent as they used to be!).

In short - take Carey's advice.
 
Marshal
Posts: 80624
470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To put what Tim said another way: stop using java.util.Date, Java.util.Calendar and its subclasses. The newer (only seven years old) classes are decsribed in the Java™ Tutorials, and they are much better.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic