Solved

Dates in Java

Posted on 2007-11-19
5
304 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Chrome and Firefox Java 5 88
Html Table Looping (part 2) 5 41
passing enum to a method 4 51
Netbeans and org.apache.commons.lang3 issue 3 55
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

751 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