Date and Time function In javascript

technical talkiess
0

 <!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>date and time in javascript</title>

</head>

<body>

    <div class="container">

        current time is : <span id="dt"></span>

    </div>

    <script>

        // date object in javascript 

        let time = new Date();

        // console.log(time);

        // output of the function is ..... Wed Jun 22 2022 11:09:17 GMT+0530 (India Standard Time)

       

       

        // if you have put any parameter in the function then he add seconds to the  adding miliseconds

        let time1 = new Date(10000);

        // console.log(time1);

        // output .......  Thu Jan 01 1970 05:30:10 GMT+0530 (India Standard Time)


// adding the date return day and date 

 let time2 = new Date("2022-06-23");

// console.log(time2);


// output .... Thu Jun 23 2022 05:30:00 GMT+0530 (India Standard Time)



// new Date(year, month, date, hours, minutes, seconds, milliseconds);

 let time3 = new Date(2022,6,24,8,25,5,2);

// console.log(time3);

// output .....Mon Jul 25 2022 01:25:25 GMT+0530 (India Standard Time)


// this function return year minute 

console.log(time3.getFullYear());

console.log(time3.getMonth());

console.log(time3.getDay());

console.log(time3.getHours());

console.log(time3.getMinutes());

console.log(time3.getSeconds());

console.log(time3.getMilliseconds());



// setdate function .... return the seconds from Jan 01 1970 05:30:10 this date

console.log(time.setDate(8));

// output .... 1657248905002 .... if you put this seconds in date object so you can get todat date


console.log(time.setMinutes(18));




setInterval(updatetime,1000);


function updatetime(){

dt.innerHTML = new Date();

}

</script>


</body>

</html>

Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)