Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Calander Class get Current Date and compare

Status
Not open for further replies.

kondakindi

IS-IT--Management
Apr 18, 2005
31
0
0
US
Hi,
I have a Date coming from a string variable of a form into a servlet .where i compare the date i it is greater than current date it gives always error invalid start date
the code is as follows could u tell me what is the error as i have used calendar class



String syear="2005";
String smonth="7";
String sdate="18";

Calendar sCalendarDate = Calendar.getInstance();
sCalendarDate.set((new Integer(smonth).intValue()),(new Integer(sdate).intValue()),(new Integer(syear).intValue()));

Calendar eCalendarDate = Calendar.getInstance();
eCalendarDate.set((new Integer(emonth).intValue()),(new Integer(edate).intValue()),(new Integer(eyear).intValue()));

Calendar nowCalendarDate = Calendar.getInstance();
if(sCalendarDate.before(nowCalendarDate))
System.out.println("Should be not less than current date"+sdate+smonth+syear);

else

System.out.println("valid");

if(eCalendarDate.before(nowCalendarDate) || (eCalendarDate.before(sCalendarDate)))
System.out.println("The End Date of the Job being posted must be later than the current Date!");

else

System.out.println("valid endadate");
Is it that i cannot use calander class to compare becoz when i print the noeCalendarDate it gives a big para

Do let me know
Thanks
 
1) check for deprecated APIs in the Date and Calendar classes, if memory serves you're using several of them.
2) consider what the data is that is filling your current date when you do Calendar.getInstance() and what data you are comparing it to.
hint: Consider that Calendar can be used with times as well as dates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top