close

 

Get Current Time 

 

語法 : 

  <?php

           date_default_timezone_set('Asia/Taipei') ;

           echo 'Current time : '.date('Y/m/d H:i:s O ') ; // O = 時區

    ?>

 

進階運用 ( 動態的得到當前時間 + 距離聖誕節的時間 )

 

 

 

--------------------------------------------------------------------------------------

 /*****************

       HTML 部分

*****************/

 
  
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
function get_result()
{
    var url = 'response.php' ;
    var formdata =
    {
        'second'        : $('[name=second]').val(),
        'days'            : $('[name=days]').val()
    };
    $.ajax({
            url        : url,
            type    : 'POST',
            data    : formdata,
            cache    : false,
            timeout : 0
        }).done
        (
        function(data) 
        {    
            if (data.length > 0 )
            {
                var field = data.split(',');
                if (field.length > 0)
                {
                    console.info(field);
                    $('[name=second]').val(field[0]);
                    $('[name=days]').val(field[1]);
                    setTimeout(get_result,1000);
                }
            }
        }
        );
}


function initvalue()
{
    get_result();
}
</script>
</head>

<body onload="initvalue()">
 

距離 2017年聖誕節 <br>還有 : <input type = "text" name="second">秒,共 <input type ="text" name ="days">天。
 
 
</form>
</body>
</html>
 

 

 
  
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
function get_result()
{
    var url = 'response.php' ;
    var formdata =
    {
        'second'        : $('[name=second]').val(),
        'days'            : $('[name=days]').val()
    };
    $.ajax({
            url        : url,
            type    : 'POST',
            data    : formdata,
            cache    : false,
            timeout : 0
        }).done
        (
        function(data) 
        {    
            if (data.length > 0 )
            {
                var field = data.split(',');
                if (field.length > 0)
                {
                    console.info(field);
                    $('[name=second]').val(field[0]);
                    $('[name=days]').val(field[1]);
                    setTimeout(get_result,1000);
                }
            }
        }
        );
}


function initvalue()
{
    get_result();
}
</script>
</head>

<body onload="initvalue()">
 

距離 2017年聖誕節 <br>還有 : <input type = "text" name="second">秒,共 <input type ="text" name ="days">天。
 
 
</form>
</body>
</html>
 

 

 

 

--------------------------------------------------------------------------------------

 /*****************

       PHP 部分

*****************/

<?php
     date_default_timezone_set('Asia/Taipei');
     $second = mktime(0,0,0,12,25,2017)-time();
     $day = $second / (24*60*60);
     echo $second.','.$day;
?>

--------------------------------------------------------------------------------------

 

顯示結果 :

 

 

 

arrow
arrow
    全站熱搜

    Eric 發表在 痞客邦 留言(0) 人氣()