Reputation: 61
I do not understand why the output to the date that I have set (2013, 01, 21) gets displayed as: Thu Feb 21 23:05:18 GMT2013. Instead of January, the output here is Feb??
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class date {
public static void main(String[] args) {
Calendar myCal = Calendar.getInstance();
myCal.set(2013,01,21);
Date bestBeforeDate = myCal.getTime();
System.out.println(bestBeforeDate);
Upvotes: 0
Views: 24
Reputation: 178253
Because months are ranged 0-11 in Java, 0 being January, 1 being February, ...
The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.
Upvotes: 2