Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Is it a bug in jdk1.3? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is it a bug in jdk1.3?" Watch "Is it a bug in jdk1.3?" New topic
Author

Is it a bug in jdk1.3?

walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 154
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 !!!


public class Walter { public boolean is_Working_Now (boolean is_boss_Coming) { return is_boss_Coming; }
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
That is an offset on an array.
0 = Jan
1 = Feb etc.


"JavaRanch, where the deer and the Certified play" - David O'Meara
walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 154
but why day=18 not 17?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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
 
subject: Is it a bug in jdk1.3?