dポイントプレゼントキャンペーン実施中!

初歩的質問で申し訳ないのですが、ご存知の方ご教授ください。日付の加算についてどうしてもわからない箇所があります。
Calendar cal= Calendar.getInstance((TimeZone.getTimeZone("GMT")));
int year = 2007;
int month = 1;
int day = 1;
cal.set(year,month,day);
cal.add(Calendar.DAY_OF_MONTH,100);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
String tempDate=sdf.format(date);
tempDate=2007/05/12

私が求めている結果は tempDate=2007/4/11 なのですが、tempDate=2007/05/12になってしまいます。
お願いします。
環境:WinXp pro Eclipse 3.1 JDK 1.4.2
2007/4/11は Oracle8i の実行結果です。
select to_date('2007-01-01') +100 from dual

A 回答 (2件)

http://java.sun.com/j2se/1.4.2/docs/api/java/uti …

Sets the values for the fields year, month, and date. Previous values of other fields are retained. If this is not desired, call clear first.

Parameters:
year - the value used to set the YEAR time field.
month - the value used to set the MONTH time field. 【Month value is 0-based. e.g., 0 for January.】
date - the value used to set the DATE time field.

2007年1月 31日
2007年2月 28日
2007年3月 31日
2007年4月 11日 → 1月1日に足しているので日付だけ足すと31+28+31+11=101

2007年2月 28日
2007年3月 31日
2007年4月 30日
2007年5月 12日 (28+31+30 + 12 = 101)
    • good
    • 0
この回答へのお礼

詳細書いていただき有難うございました。勉強します。

お礼日時:2008/03/12 11:26

int year = 2007;


int month = 1;
int day = 1;

要するに、これだと「2007年2月1日」になるよ、って話です。
1月1日なら、int month = 0;
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!