Highstock - display number of week

前端 未结 3 656
盖世英雄少女心
盖世英雄少女心 2021-01-22 17:23

How can I show the week number for the date in Highstock (not Highcharts!)?

My SQL looks like this

select unix_timestamp(date)*1000 week         


        
3条回答
  •  礼貌的吻别
    2021-01-22 18:07

    For @Paweł Fus 's answer, I find out that when the date is 2012/1/1 witch was Sunday,the result is wrong, so I have changed the answer to :

    W: function (timestamp) {
        var date = new Date(timestamp);
        var firstDay = new Date(date.getFullYear(), 0, 1); 
        var day = firstDay.getDay() == 0 ? 7 : firstDay.getDay();
        var days = Math.floor((date.getTime() - firstDay)/86400000) + day; // day numbers from the first Monday of the year to current date
        return Math.ceil(days/7);
    },
    

提交回复
热议问题