0 points

JS Get the current Date & Time


dashboard

Sun Jul 19 2020 16:44:35 GMT+0000 (UTC)

Posted by @PotatoGLaDOS #javascript

        //Gets the Current Date and Time
        var todayDate = new Date();

        //Gets the Date Values
        var dd = ("0" + todayDate.getDate()).slice(-2);
        var mm = ("0" + (todayDate.getMonth() + 1)).slice(-2);
        var yyyy = todayDate.getFullYear();
        document.getElementById('currentDate').innerHTML = mm + " / " + dd + " / " + yyyy;

        //Gets the Time Values
        var hh = ("0" + todayDate.getHours()).slice(-2);
        var min = ("0" + todayDate.getMinutes()).slice(-2);
        var ss = ("0" + todayDate.getSeconds()).slice(-2);
        document.getElementById('currentTime').innerHTML = hh + " : " + min + " : " + ss;

        //Sets the Current Data
        var currentMonth = ("0" + (todayDate.getMonth() + 1)).slice(-2);
        var currentHour = (("0" + todayDate.getHours()).slice(-2)) * 100;
content_copy Copy

Coded in Visual Studio Code, ran in Chrome