Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to print current date in html div using Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 294
    Comment on it

    Hello Reader's If you want to show current date in a html div, Then you can genrate it in JS then show back to html. Here is the example below:-

    <div id="Console"></div>
    

    Now the script will go like this:-

    window.onload = function() {
        var now = new Date();
        var strDateTime = [[AddZero(now.getDate()), AddZero(now.getMonth() + 1), now.getFullYear()].join("/"), [AddZero(now.getHours()), AddZero(now.getMinutes())].join(":"), now.getHours() >= 12 ? "PM" : "AM"].join(" ");
        document.getElementById("Console").innerHTML = "Now: " + strDateTime;
    };
    
    function AddZero(num) {
        return (num >= 0 && num < 10) ? "0" + num : num + "";
    }
    

    Output:-

    Now: 09/12/2015 16:08 PM
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: