読者です 読者をやめる 読者になる 読者になる

「今月の第3月曜日」の日付を求める

groovy

ソース

cal = Calendar.getInstance()
cal.set(Calendar.DAY_OF_WEEK_IN_MONTH,3)
cal.set(Calendar.DAY_OF_WEEK,2)
cal.getTime().format("yyyy/MM/dd")


calNG = Calendar.getInstance();
calNG.set(Calendar.WEEK_OF_MONTH,3);
calNG.set(Calendar.DAY_OF_WEEK,2);
calNG.getTime().format("yyyy/MM/dd")

実行環境

実行結果

groovy:000> load D:\workspace\groovy_SandBox\3rdMonday.groovy
===> java.util.GregorianCalendar[time=1261827137281,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Tokyo",offset=32400000,dstSavings=0,useDaylight=false,transitions=10,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2009,MONTH=11,WEEK_OF_YEAR=52,WEEK_OF_MONTH=4,DAY_OF_MONTH=26,DAY_OF_YEAR=360,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=8,HOUR_OF_DAY=20,MINUTE=32,SECOND=17,MILLISECOND=281,ZONE_OFFSET=32400000,DST_OFFSET=0]
===> null
===> null
===> 2009/12/21
===> java.util.GregorianCalendar[time=1261827137468,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Tokyo",offset=32400000,dstSavings=0,useDaylight=false,transitions=10,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2009,MONTH=11,WEEK_OF_YEAR=52,WEEK_OF_MONTH=4,DAY_OF_MONTH=26,DAY_OF_YEAR=360,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=8,HOUR_OF_DAY=20,MINUTE=32,SECOND=17,MILLISECOND=468,ZONE_OFFSET=32400000,DST_OFFSET=0]
===> null
===> null
===> 2009/12/14

Calendar.WEEK_OF_MONTHは間違い。第3週目の月曜日になってしまう。

広告を非表示にする