Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it a bug in jdk1.3?

 
walter wang
Ranch Hand
Posts: 159
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all
Try this
import java.util.*;
import java.util.Date;
import java.text.DateFormat;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import java.util.Locale;
import java.text.NumberFormat;
import java.text.DecimalFormat;
/**
* This class represents a calender
*/
public class Test{


public static void main(String args[]){
Calendar orderDate = Calendar.getInstance();
System.out.println(orderDate);
}
}
result is [Year=2002, Month=5, Day=18]
but i think should be Month=6 !!!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is an offset on an array.
0 = Jan
1 = Feb etc.
 
walter wang
Ranch Hand
Posts: 159
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but why day=18 not 17?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the folks who wrote the Calendar class were on crack at the time. :roll: Really, there's no good reason for it, but at least the 0 and 1 starting points of the various fields are documented in the API. You just have to read the API carefully when using Calendar - "common sense" will not work here.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because dates are intinsically numbers anyway so they just aligned them. Months have names that are strings.
From the API


DATE
public static final int DATEField number for get and set indicating the day of the month. This is a synonym for DAY_OF_MONTH. The first day of the month has value 1.



MONTH
public static final int MONTHField number for get and set indicating the month. This is a calendar-specific value. The first month of the year is JANUARY which is 0; the last depends on the number of months in a year.

[ June 18, 2002: Message edited by: Cindy Glass ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic