【问题标题】:Get Friday Dates of Year in javascript using jquery [closed]使用jquery在javascript中获取一年中的星期五日期[关闭]
【发布时间】:2013-03-06 12:29:21
【问题描述】:

我有一个名为 Reporting date 的字段,它应该给我一个 Dates 下拉列表以及 Friday Reporting Dates 列表。特定财政年度的格式 (YYYY-MM-DD W1)。 W 代表 W,它应该显示那一年的周数。 我想为此使用Jquery。有人可以帮忙吗?

【问题讨论】:

  • 请向我们展示一些您尝试过的代码

标签: javascript jquery date


【解决方案1】:

请查看下面用java脚本编写的代码。

<!DOCTYPE html>
<html>
<body>
    <script>
        var x = new Date();
       //set the financial year starting date
        x.setFullYear(2013, 03, 01);

       //set the next financial year starting date
            var y = new Date();
        y.setFullYear(2014, 03, 01);
        var j = 1;
        var count = 0;

      //getting the all fridays in a financial year
        for ( var i = 0; x<y; i += j) {
            if (x.getDay() == 5) {
                document.write("Date : " + x.getDate() + "/"
                        + (x.getMonth() + 1) + "<br>");
                x = new Date(x.getTime() + (7 * 24 * 60 * 60 * 1000));
                j = 7;
                count++;
            } else {
                j = 1;
                x = new Date(x.getTime() + (24 * 60 * 60 * 1000));
            }
        }
        document.write("total fridays : " + count + "<br>");
    </script>
</body>
</html>

这将返回一个财政年度中的所有星期五。您可以根据自己的要求进行修改。

【讨论】:

  • 如果 1 月 1 日是星期六,第一个营业星期五是前一年的 12 月 31 日。一年中的第一 (ISO) 周是包含星期四或 1 月 4 日的第一周。
猜你喜欢
  • 2016-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多