Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Date and Time (tough one!)

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,
This has me STUMPED!
I want to check to see if the date a person enters is before or after 6 PM tomorrow. The date the user enters comes in the format MM/dd/yyyy. If it's currently before 6:00 PM then they are allowed to enter tomorrow's date or later (but not today�s date). If it's currently AFTER 6 PM, then they can only enter the day after tomorrow or later. This seems easier than it is but, for the life of me, I just can't figure it out. If anyone can help I'd really really apprecaite it. Here's what I have so far. Can anyone stear me in the right direction?
Calendar requestedDate = new GregorianCalendar();
Calendar tommorrow = new GregorianCalendar();
tommorrow.add(tommorrow.DATE, 1);
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String date = "3/20/2002";
Date parseDate = df.parse(date);
requestedDate.setTime(parseDate);
if(requestedDate.equals(tommorrow) || requestedDate.after(tommorrow) && now.get(Calendar.HOUR_OF_DAY) < 14)
{
System.out.println("no problem entering");
}
else
{
System.out.println("problems entering");
}
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Problem in your code lies in the calendar objects you've created.
If you dont mention any arguments while creating these GregorianCalendar objects, those will be treated as those objects which show the current date and time.
so the code should look like this :

I hope this helps
cheers
sivaPrasad
reply
    Bookmark Topic Watch Topic
  • New Topic