用JS計算預計時間與現在時間的差

來源:互聯網
上載者:User

標籤:split   doc   highlight   utf-8   table   cti   link   boot   title   

1.我用的是bootstrap網格布局,首先要引入bootstrap類。

(1)<script src="jquery-1.11.2.min.js"></script>

(2)<script src="bootstrap.min.js"></script>

(3)<link href="bootstrap.min.css" rel="stylesheet" type="text/css"/>

2.製作表格

 

3.網格布局.我用col-xs是最小可以在手機大小實現不亂

<!doctype html><html lang="en"><head><meta charset="UTF-8" /><title>退房提醒</title><script src="jquery-1.11.2.min.js"></script><script src="bootstrap.min.js"></script><link href="bootstrap.min.css" rel="stylesheet" type="text/css"/></head><body><div class="container"><br /><div class="row">    <div class="col-xs-12">退房提醒</div>    <div class="col-xs-0"></div>    </div>        <div class="row">            <div class="col-xs-12">                <table class="table" border="1" cellpadding="1" cellspacing="2">                                                  <thead>                        <tr class="success">                            <th>序號</th>                            <th>房間號</th>                            <th>客戶姓名</th>                            <th>預計退房時間</th>                            <th>操作</th>                        </tr>                    </thead>                    <tbody id="neirong">                                                    </tbody>                </table>            </div>    </div></div>    </body>

 運行結果:

4.用ajas實現功能:

<script type="text/x-javascript">$.ajax({url:"tixingchuli.php",dataType:"TEXT",type:"POST",success: function(bb){}       });</script></html>

 5.做處理頁面

tixingchuli.php

<?phpinclude("DBDA.class.php");//引入類$db = new DBDA();$sql = "select * from ruzhu";//訪問資料庫ruzhu表裡所有$ab = $db->StrQuery($sql);echo $ab;?>

 


 6.回到首頁面給取到的字串拆分

$.ajax({url:"tixingchuli.php",dataType:"TEXT",type:"POST",success: function(bb){//alert(bb);var hang=bb.split("|");var str="";var da=new Date();for(var i=0;i<hang.length;i++){var lie=hang[i].split("^");var aa=Date.parse(new Date(lie[10]));//取回來的資料轉換為時間戳記var cha=da.getTime()-aa;//求目前時間與預留時間的差。用目前時間減去預計時間就求出他們的差var cha1=Math.ceil(cha/3600000);//用Math.ceil();方法向上取整。再除以24就取的天str=str+"<tr><td>"+lie[0]+"</td><td>"+lie[1]+"</td><td>"+lie[3]+"</td><td>"+lie[10]+"</td><td>還剩"+cha1+"小時</td></tr>";}$("#neirong").html(str);}});
</script>
</html>

 

 

用JS計算預計時間與現在時間的差

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.