datum in javascript

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Onbekend onbekend

onbekend onbekend

31/01/2010 21:24:00
Quote Anchor link
Weet een van jullie misschien hoe je op basis van een gegeven weeknummer en jaartal de datums van die week kan berekenen in javascript?

voorbeeld;
-- input
jaar 2010
week 4

-- result
25-01-2010
26-01-2010
27-01-2010
28-01-2010
29-01-2010
30-01-2010
31-01-2010

thnx.
 
PHP hulp

PHP hulp

19/04/2024 21:15:58
 
Onbekend onbekend

onbekend onbekend

01/02/2010 18:46:00
Quote Anchor link
Iemand?
 
Gerben Jacobs

Gerben Jacobs

01/02/2010 19:03:00
Quote Anchor link
Edit: godver ik maak er een zooitje van. Hoe dan ook. Hier heb je wat functies, hoop dat je er wat mee kan, zoek de logica zelf maar uit.


Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function getBoundaries(dObj, dayFirst, dayLast)
{
    var bounds = new Array();
    bounds[0] = new Date(dObj.getFullYear(), dObj.getMonth(), (dObj.getDate() + dayFirst));
    bounds[1] = new Date(dObj.getFullYear(), dObj.getMonth(), (dObj.getDate() + dayLast));
    return bounds;
}
    
function getWeekBoundaries(today)
{
    var day = today.getDay();
    var startday = 1; // 0 = Sunday 1 = Monday
        var bounds;
    switch (day)
    {
        case 0:
            bounds = (startday) ? getBoundaries(today, 7, 0) : getBoundaries(today, 0, 6);
        break;
        case 1:
            bounds = (startday) ? getBoundaries(today, 0, 6) : getBoundaries(today, -1, 5);
        break;
        case 2:
            bounds = (startday) ? getBoundaries(today, -1, 5) : getBoundaries(today, -2, 4);
        break;
        case 3:
            bounds = (startday) ? getBoundaries(today, -2, 4) : getBoundaries(today, -3, 3);
        break;
        case 4:
            bounds = (startday) ? getBoundaries(today, -3, 3) : getBoundaries(today, -4, 2);
        break;
        case 5:
            bounds = (startday) ? getBoundaries(today, -4, 2) : getBoundaries(today, -5, 1);
        break;
        case 6:
            bounds = (startday) ? getBoundaries(today, -5, 1) : getBoundaries(today, 7, 0);
        break;
    }
    return bounds;
}
Date.prototype.getWeek = function()
{
    var thisDate = this;
    var year = thisDate.getFullYear();
    var month = thisDate.getMonth();
    var day = thisDate.getDate();

    month += 1;

    var a = Math.floor((14-(month))/12);
    var y = year+4800-a;
    var m = (month)+(12*a)-3;
    var jd = day + Math.floor(((153*m)+2)/5) +
                 (365*y) + Math.floor(y/4) - Math.floor(y/100) +
                 Math.floor(y/400) - 32045;

    var d4 = (jd+31741-(jd%7))%146097%36524%1461;
    var L = Math.floor(d4/1460);
    var d1 = ((d4-L)%365)+L;
    NumberOfWeek = Math.floor(d1/7) + 1;
    return NumberOfWeek;        
}
Gewijzigd op 01/01/1970 01:00:00 door Gerben Jacobs
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.