Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Carey Brown
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • 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: 23055
157
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: 71747
312
  • 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.
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic