Solved

Dates in Java

Posted on 2007-11-19
5
278 Views
Last Modified: 2010-03-30
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
Comment
Question by:Messenger569
  • 2
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
cmalakar earned 250 total points
ID: 20317736
year parameter should be substracted by 1900...

ie.,

Year = Year - 1900
Date expiration = new Date(Year, Month, 1,0 ,0 );
0
 
LVL 23

Assisted Solution

by:cmalakar
cmalakar earned 250 total points
ID: 20317764
Month takes the values between 0-11

Subtract 1 from month also
0
 
LVL 11

Expert Comment

by:Manish
ID: 20317821
Try this.
Date expiration = new Date(Year-1900, Month, 1,0 ,0 );
0
 
LVL 11

Expert Comment

by:Manish
ID: 20317823
Sorry I didnt see previous responce.
0
 
LVL 1

Expert Comment

by:TECHHEAD_biz
ID: 20317864
Actually, the above constructors are deprecated.  More correct would be:

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now