Bonjour,

A partir d'une date exprimée sous le format année-semaine-jour de la semaine,
je voudrais obtenir un objet Date.

voici mon code :
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
21
22
23
24
25
26
27
28
29
30
31
 
public static Date convertAAAASSJToDate(Integer aaaassj) {
 
		if (aaaassj == null) {
			return null;
		}
 
		String toConvert = aaaassj.toString();
 
		if (toConvert.length() < 6) {
			return null;
		}
 
		String annee = toConvert.substring(0, 4);
		String semaine = toConvert.substring(4, 6);
		String jour = "1";
 
		if (toConvert.length() > 6) {
			jour = toConvert.substring(6, 7);
		}
 
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setFirstDayOfWeek(Calendar.MONDAY);
		calendar.setMinimalDaysInFirstWeek(4);
 
		calendar.set(Calendar.YEAR, Integer.parseInt(annee));
		calendar.set(Calendar.WEEK_OF_YEAR, Integer.parseInt(semaine));
		calendar.set(Calendar.DAY_OF_WEEK, Integer.parseInt(jour));
 
		return calendar.getTime();
	}
La date retournée est bonne à un jour prés. En gros, il considère toujours que la semaine commence le dimanche.

Quelqu'un sait-il comment résoudre ce problème?

Merci