Dates in Java

I've watched the following code execute, and every time I check the date of expiration after this executes, I get something like:

Wed Feb 01 00:00:00 CST 3905

Actually, I'm getting this same date every time it executes. The values for Year and Month are (2005, 1) respectively.
String strMonth = request.getParameter("txtMonth");
String strYear = request.getParameter("txtYear");
		
int Month = Integer.parseInt(strMonth);
int Year = Integer.parseInt(strYear);
		
		
Date expiration = new Date(Year, Month, 1,0 ,0 );

Open in new window

Messenger569Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
cmalakarConnect With a Mentor Commented:
year parameter should be substracted by 1900...

ie.,

Year = Year - 1900
Date expiration = new Date(Year, Month, 1,0 ,0 );
0
 
cmalakarConnect With a Mentor Commented:
Month takes the values between 0-11

Subtract 1 from month also
0
 
ManishLeadCommented:
Try this.
Date expiration = new Date(Year-1900, Month, 1,0 ,0 );
0
 
ManishLeadCommented:
Sorry I didnt see previous responce.
0
 
TECHHEAD_bizCommented:
Actually, the above constructors are deprecated.  More correct would be:

Date expiration = ( new GregorianCalendar(Year, Month-1, 1) ).getTime();
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.