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 32 33 34 35 36 37
| <!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>test date</title>
</head>
<body>
</body>
<script>
Date.prototype.getWeek = function() {
const firstDay = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this - firstDay) / 864E5) + firstDay.getDay() + 1) / 7);
}
const now = new Date();
let div = document.createElement('div');
div.textContent = `numero de la semaine : ${new Date().getWeek()}`;
document.body.appendChild(div);
const tmp = now;
const tmp2 = now;
const monday = new Date(tmp.setDate(tmp.getDate() - tmp.getDay()%7 + 1));
const friday = new Date(tmp2.setDate(tmp2.getDate() - tmp2.getDay()%7 + 5));
console.log('lundi', monday);
console.log('vendredi', friday);
div = document.createElement('div');
div.textContent = monday.toLocaleString('fr', {weekday: 'long', day: 'numeric'});
document.body.appendChild(div);
div = document.createElement('div');
div.textContent = friday.toLocaleString('fr', {weekday: 'long', day: 'numeric'});
document.body.appendChild(div);
</script>
</html> |
Partager