Click to See Complete Forum and Search --> : get year in java


The One
03-04-2006, 05:49 AM
i got the following code:


Date toDay = new Date();
int year = toDay.getYear();
System.out.println (year);

it doesnt work. it says the year is 106.
How do i get 2006???
HELP?

Khalid Ali
03-04-2006, 09:07 AM
something along these linse will work (I am showing u the usage if date as well)


Date cdate = new Date();
Calendar gcalendar = new GregorianCalendar();
gcalendar.setTime(cdate);
System.out.println("cdate = "+gcalendar.toString()+"\nyear = "+gcalendar.get(Calendar.YEAR));