• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validation check for the day using util.

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using the following code to check the validation for the date which is entered is saturday or sunday. its not woring. Please check it.

String dateText = bookingDateText.getText();
DateFormat myDateFormat = new SimpleDateFormat("dd-mm-yyyy");
try {
int day = myDateFormat.parse(dateText).getDay();
if(day==0 || day==6){
JOptionPane.showMessageDialog(null, "Bank Holiday");
}
} catch (ParseException ex) {
System.out.println("Invalid Date Parser Exception ");
ex.printStackTrace();
}}


Can any one tell me whats wrong with this code...

Thanks in advance.

Regards,
Kiran
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a guess..
If you are not getting the correct day of week it's probably due to a problem with the date format you has specified.

i.e. the pattern for a two digit month is MM and not mm

Apart from that Date.getDay has been deprecated since jdk 1.1.

Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_WEEK).



I believe this done as follows.


[ September 15, 2008: Message edited by: Gamini Sirisena ]
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gamini has also shown you another flaw in your code. mm is used for minutes, not months. Use MM for those.

Also, Calendar.get(DAY_OF_WEEK) is not 0 based but Calendar.SUNDAY based. Calendar.SUNDAY is not 0.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:
Also, Calendar.get(DAY_OF_WEEK) is not 0 based but Calendar.SUNDAY based. Calendar.SUNDAY is not 0.



The leading cause of suicide among Java developers in the pre-Joda Time era.
 
Look ma! I'm selling my stuff!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic