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); |
Partager