Bonjour à tous,
Dans le code modifié d'un code existant, j'ai ceci (extrait):
Ce code provoque une erreur tt.getWeek is not a function à la ligne 5. D'où peut provenir cette erreur?
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 function clock() { const tt = new Date() ,myDay = parseInt(tt.getDay()) // 0 for sunday ,myWeek = parseInt(tt.getWeek()) ,myMonth= parseInt(tt.getMonth()) // 0 for january ,myYear = tt.getFullYear() ,myDate = tt.getDate() // day in month ; // Suite du code de la fonction } // This script is released to the public domain and may be used, modified and // distributed without restrictions. Attribution not necessary but appreciated. // Source: http://weeknumber.net/how-to/javascript // Returns the ISO week of the date. Date.prototype.getWeek = function() { var date = new Date(this.getTime()); date.setHours(0, 0, 0, 0); // Thursday in current week decides the year. date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); // January 4 is always in week 1. var week1 = new Date(date.getFullYear(), 0, 4); // Adjust to Thursday in week 1 and count number of weeks from date to week1. return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7); }
S'il vous faut le code complet, n'hésitez pas à me le demander.
Partager