Link to home
Start Free TrialLog in
Avatar of Messenger569
Messenger569Flag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Manish
Try this.
Date expiration = new Date(Year-1900, Month, 1,0 ,0 );
Sorry I didnt see previous responce.
Avatar of TECHHEAD_biz
TECHHEAD_biz

Actually, the above constructors are deprecated.  More correct would be:

Date expiration = ( new GregorianCalendar(Year, Month-1, 1) ).getTime();