HTML Display Current date

前端 未结 6 1309
日久生厌
日久生厌 2021-02-02 13:19

I am using website builder called \'clickfunnels\', and they don\'t support feature that would allow me to display current date. But, I can add custom html to it.

I was

相关标签:
6条回答
  • 2021-02-02 13:37

    Here's one way. You have to get the individual components from the date object (day, month & year) and then build and format the string however you wish.

    n =  new Date();
    y = n.getFullYear();
    m = n.getMonth() + 1;
    d = n.getDate();
    document.getElementById("date").innerHTML = m + "/" + d + "/" + y;
    <p id="date"></p>

    0 讨论(0)
  • 2021-02-02 13:39

    Use Date::toLocaleDateString.

    new Date().toLocaleDateString()
    = "9/13/2015"
    

    You don't need to set innerHTML, just by writing

    <p>
    <script> document.write(new Date().toLocaleDateString()); </script>
    </p>
    

    will work.

    P.S.

    new Date().toDateString()
    = "Sun Sep 13 2015"
    
    0 讨论(0)
  • 2021-02-02 13:47
    var currentDate  = new Date(),
        currentDay   = currentDate.getDate() < 10 
                     ? '0' + currentDate.getDate() 
                     : currentDate.getDate(),
        currentMonth = currentDate.getMonth() < 9 
                     ? '0' + (currentDate.getMonth() + 1) 
                     : (currentDate.getMonth() + 1);
    
    document.getElementById("date").innerHTML = currentDay + '/' + currentMonth + '/' +  currentDate.getFullYear();
    

    You can read more about Date object

    0 讨论(0)
  • 2021-02-02 13:56

    This helped me:

    <p>Date/Time: <span id="datetime"></span></p><script>var dt = new Date();
    document.getElementById("datetime").innerHTML=dt.toLocaleString();</script>    
    
    0 讨论(0)
  • 2021-02-02 13:57
      <script >
    window.onload = setInterval(clock,1000);
    function clock()
    {
        var d = new Date();
        var date = d.getDate();
        var year = d.getFullYear();
        var month = d.getMonth();
        var monthArr = ["January", "February","March", "April", "May", "June", "July", "August", "September", "October", "November","December"];
        month = monthArr[month];
        document.getElementById("date").innerHTML=date+" "+month+", "+year;
    }
    

    0 讨论(0)
  • 2021-02-02 14:01

    I prefer to use

    <input type='date' id='hasta' value='<?php echo date('Y-m-d');?>'>
    

    that works well

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