HTML how do I insert dynamic date in webpage

前端 未结 8 2056
暖寄归人
暖寄归人 2021-01-05 14:40

I have a static webpage, nothing changes dynamically. However the client wants a date insert into text within the page. The date will always be the current daet plus one day

相关标签:
8条回答
  • 2021-01-05 15:35

    Use JavaScript and insert the date onLoad.

    Take a look here for a working example: http://jsfiddle.net/xGDvp/

    This will update the date as follows: February 5, 2011

    Your HTML:

    <span id="spanDate"></span>
    

    Your Javascript

        <script type="text/javascript">
               var months = ['January','February','March','April','May','June','July',
    'August','September','October','November','December'];       
    var tomorrow = new Date();
    tomorrow.setTime(tomorrow.getTime() + (1000*3600*24));       
    document.getElementById("spanDate").innerHTML = months[tomorrow.getMonth()] + " " + tomorrow.getDate()+ ", " + tomorrow.getFullYear();
        </script>
    
    0 讨论(0)
  • 2021-01-05 15:36

    If your not opposed to PHP, then you could do something like this... Also Tizag.. http://www.tizag.com/phpT/phpdate.php

    <?php
    $todayPlusADay = mktime(0, 0, 0, date("m"), date("d")+1, date("y"));
    echo "Todays Date Plus One Day (Tomorrow) ".date("m/d/y", $todayPlusADay); 
    ?>
    

    Quick search for "php echo date + 1 day" produced that little diddy :) That could certainly be expanded upon to any extent just about.

    0 讨论(0)
提交回复
热议问题