如何确定给定日期的工作日?

时间:2017-04-28 09:37:48

标签: php

如何显示输入的出生日期的工作日(星期一至星期日)?此代码将显示年,月,日(数量),我试图找到如何显示工作日但却失败了很多次并感到沮丧。

<!DOCTYPE HTML>
<html>
    <head>
        <title>Age calculator</title>
        <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
        <link rel="stylesheet" href="https://formden.com/static/cdn/bootstrap-iso.css"/>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/> 
    </head>
    </head>
    <body>
        <?php
            error_reporting(0);
            if(isset($_POST['submit'])){
                $dateOfBirth = $_POST['dateOfBirth'];
                $today = date("Y-m-d");
                $diff = date_diff(date_create($dateOfBirth),date_create( $today));
                $output= $diff->format('%y Years, %m Months, %d Days'); 
            } 
        ?>
        <form method="post" action="">
            <input type="text" name="dateOfBirth" id="dob" />
            <input type="submit" value="submit" name="submit" /><br>
            <?php
                echo $output;
            ?>
        </form>

        <script>
            $(document).ready(function(){
              var date_input=$('input[name="dateOfBirth"]'); //our date input has the name "date"
              var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
              var options={
                format: 'mm/dd/yyyy',
                container: container,
                todayHighlight: true,
                autoclose: true,
                orientation: "top left",
              };
              date_input.datepicker(options);
            })

            function show_now(){
                var my_day=new Date(dob)
                //var dt = new Date(\"Aug 16, 2005 05:55:00\");
                var day_name=new Array(7);
                day_name[0]='Sunday'
                day_name[1]=' Monday'
                day_name[2]='Tuesday'
                day_name[3]='Wednesday'
                day_name[4]='Thursday'
                day_name[5]='Friday'
                day_name[6]='Saturday'

                alert ("Today Day is  = " + day_name[my_day.getDay(dob)]); 
            }
        </script>
    <body>
        <input type=button value="Show Day" onclick="show_now();">
    </script>
    </body>
</html> 

1 个答案:

答案 0 :(得分:0)

您可以使用日期功能和格式选项'w'显示星期几。

Derived::Derived(std::ostream& stream) : Base(), Redirection(stream) {}

有关详细信息,请参阅w3school date function