bonjour,
dans mon application, je récupère une string qui représente une date.
Je voudrai afficher le mois en lettre et toujours en anglais.
Donc je récupère le numéro de mon mois à partir de ma string mais ensuite ...
Voilà ce que j'ai fait :
Le problème est qu'après avoir formatter ma date (myAccCal), j'ai avancé d'un mois !?!, par exemple je récupère 'Décembre' alors que le numéro de mon mois est '11'
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 StringBuffer month = new StringBuffer(); FieldPosition fp = new FieldPosition(DateFormat.MONTH_FIELD); NumberFormat formatter = new DecimalFormat("00"); DateFormat df = DateFormat.getDateInstance(DateFormat.LONG); // Get the year and the month in a number format Accounting_Year = Accounting_Period.substring(0, 4); Curr_Month_Id = Accounting_Period.substring(4, 6); // Creating date type object to get month in letter format Calendar myAccCal = new GregorianCalendar(new Integer(Accounting_Year).intValue(), new Integer(Curr_Month_Id).intValue(), Calendar.DAY_OF_MONTH); df.format((Object)myAccCal.getTime(), month, fp); Acc_Curr_Month = month.substring(fp.getBeginIndex(), fp.getEndIndex()).toString(); // First letter UpperCase Acc_Curr_Month = Acc_Curr_Month.substring(0,1).toUpperCase() + Acc_Curr_Month.substring(1, Acc_Curr_Month.length());
Pour la langue comment préciser Locale.US une fois que l'on créer son GregorianCalendar ?
Partager