• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

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

0
Messenger569
Asked:
Messenger569
  • 2
  • 2
2 Solutions
 
cmalakarCommented:
year parameter should be substracted by 1900...

ie.,

Year = Year - 1900
Date expiration = new Date(Year, Month, 1,0 ,0 );
0
 
cmalakarCommented:
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now