Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic