Javascript多个工时从日期到现在计算

时间:2016-06-27 07:57:52

标签: javascript

我需要像这样的javascript



    // Calculate days since 7st May 2016
    var initialDate = new Date(2016, 5, 7);
    var now = Date.now();
    var difference = now - initialDate;
    var millisecondsPerDay = 24 * 60 * 60 * 1000;
    var daysSince = Math.floor(difference / millisecondsPerDay);

    // Write result to HTML
    document.getElementById('days_since').innerHTML = daysSince;

<div id="days_since"></div>
&#13;
&#13;
&#13;

但我想显示几个小时,我的工作是例如。星期一,星期五,上午10点到下午6点,每个星期六上午11点到下午3点。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您好请参阅此http://jsfiddle.net/yentup/fKA9X/1/

<强> JS

$(function(){
    var calcNewYear = setInterval(function(){
        date_future = new Date(new Date().getFullYear() +1, 0, 1);
        date_now = new Date();

        seconds = Math.floor((date_future - (date_now))/1000);
        minutes = Math.floor(seconds/60);
        hours = Math.floor(minutes/60);
        days = Math.floor(hours/24);

        hours = hours-(days*24);
        minutes = minutes-(days*24*60)-(hours*60);
        seconds = seconds-(days*24*60*60)-(hours*60*60)-(minutes*60);

        $("#time").text("Time until new year:\nDays: " + days + " Hours: " + hours + " Minutes: " + minutes + " Seconds: " + seconds);
    },1000);
});

HTML

<div id="time"></div>