I am writing a class to simplify all the operations that I could make with a GregorianCalendar. The operations that I need to make are: -Getting the date in string format, translated to Italian; -Making the subtraction between two dates. I havent' used Calendar,Date and Time classes because they have a lot of deprecated methods. Also, the tag isn't gregoriancalendar because I may need to use another class (but feel free to modify it if not agree). However this is the class:
package TruckingCompany;
import java.util.GregorianCalendar;
import java.util.Locale;
@SuppressWarnings("serial")
public class TCCalendar extends GregorianCalendar
{
public TCCalendar()
{
super(Locale.ITALY);
}
@Override
public String toString()
{
String str=new String();
switch(get(DAY_OF_WEEK))
{
case 1:
str+="Domenica ";
break;
case 2:
str+="Lunedì ";
break;
case 3:
str+="Martedì ";
break;
case 4:
str+="Mercoledì ";
break;
case 5:
str+="Giovedì ";
break;
case 6:
str+="Venerdì ";
break;
case 7:
str+="Sabato ";
break;
}
str+=get(DAY_OF_MONTH);
switch(get(MONTH))
{
case 0:
str+=" Gennaio ";
break;
case 1:
str+=" Febbraio ";
break;
case 2:
str+=" Marzo ";
break;
case 3:
str+=" Aprile ";
break;
case 4:
str+=" Maggio ";
break;
case 5:
str+=" Giungo ";
break;
case 6:
str+=" Luglio ";
break;
case 7:
str+=" Agosto ";
break;
case 8:
str+=" Settembre ";
break;
case 9:
str+=" Ottobre ";
break;
case 10:
str+=" Novembre ";
break;
case 11:
str+=" Dicembre ";
break;
}
str+=get(YEAR)+ " Ore ";
str+=get(HOUR_OF_DAY)+ ":";
str+=get(MINUTE)+":";
str+=get(SECOND);
return str;
}
}
I use linux and the time is correctly set to 10:19 (Italian hour).
But now (at 10:20 local hour) I get as result of the toString method:
"Venerdì 2 Marzo 2012 Ore 13:21:10"
Don't look at the Italian stuff, the problem is the hour: get(HOUR_OF_DAY) returns 13 instead of 10 (22:21).
Also, there is another class more intuitive? I have searched in javadoc and except Calendar,GregorianCalendar, Date and Time I haven't found anything else.