Bonjour,

J'ai réussi à avoir la date du jour au format JJ/MM/AAAA , mais cela prends tout de même 13 lignes , n'existe t'il pas un moyen plus simple ?

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
17
18
19
20
Date dateJour= new Date();
/* calcul du jour */
FieldPosition posChamp = new FieldPosition(DateFormat.DATE_FIELD);
StringBuffer sb = new StringBuffer();
DateFormat format1 = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.FULL,Locale.FRENCH);
sb = format1.format(dateJour, sb, posChamp);
String day=sb.substring(posChamp.getBeginIndex(), posChamp.getEndIndex());
/* calcul du mois */
FieldPosition posChamp2 = new FieldPosition(DateFormat.MONTH_FIELD);
sb = format1.format(dateJour, sb, posChamp2);
String month=sb.substring(posChamp2.getBeginIndex(), posChamp2.getEndIndex());
/* calcul de l'année */
FieldPosition posChamp3 = new FieldPosition(DateFormat.YEAR_FIELD);
DateFormat format2 = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.FRENCH);
sb = format2.format(dateJour, sb, posChamp3);
String year=sb.substring(posChamp3.getBeginIndex(), posChamp3.getEndIndex());
/* cancaténation Jour , mois , années */
String dateDuJour = day+"/"+month+"/"+year;
 
System.out.println("voici la date formatée : "+dateDuJour);
Enfin cela marche mais c'est lourd !