Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dates in Java

Posted on 2007-11-19
5
Medium Priority
?
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
cmalakar earned 1000 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

688 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