Skip to main content

Countdowns timer of 2021 in JavaScript language

In this tutorial  we will see that how to make countdown timer using javascript  language so friend if you are a bignner and you don't have any  idea about it .

 so don't worry because in this tutorial  made for bignner .it this tutorial full explain step by step which by any visiter can understand  of this very easly



Let's  break it 

1.   first we need to create variable and get date of paste or future through Date method 

and enter your Month name Date, years, hour, minutes, second like this

    //here i created a object then get time in milliseconds from this date, check DOB

        var d = new Date("Jan 1,2021  00: 00:01");
// you can also do like this
var variable_name= new Date("Month 1,year,hour,minutes,second");

//script tag is not close it is example




2. Now we will creat a function and in this block we get present time through   

this method like this

  function myFunction() {


            //object for date present date
            var nowDate = new Date();
            // again i get time in milliseconds of present date
            var again = nowDate.getTime();
//you can also do this like
var variable_name= new Date().getTime();

//script tag is not close it is example



2. Here we will get different between future/paste time- and present time.
see this example of from code-source :

 <script>
        //here i created a object then get time in milliseconds from this date, check DOB

        var d = new Date("Jan 1,2021  00: 00:01");
        var final = d.getTime();
        var well = "2021 will coming soon";


        function myFunction() {



            //object for date present date
            var nowDate = new Date();
            // again i get time in milliseconds of present date
            var again = nowDate.getTime();


            // now different between "d" and "again"
            var different = final - again;


          //script tag is not close it is example



3.  Here we will change of this var different value in day and month and minutes and also in second. like this :

           
var days = Math.floor(different / (1000 * 60 * 60 * 24));
            // change of this different in hours
            var hours = Math.floor((different % (1000 * 60 * 60 * 24)) 
/ (1000 * 60 * 60));
            // change of this different in minutes
            var minutes = Math.floor((different % (1000 * 60 * 60)) / (1000 * 60));

            //change of this different in seconds
            var seconds = Math.floor((different % (1000 * 60)) / 1000);



          //script tag is not shown it is example


3.  Print all this changed variable . you can also show this in defferent-defferent 
type but i used this method 
example from source-code:

            //here i am printing of this all days, hours , minutes, seconds

  document.getElementById("demo").innerHTML = well + "<br>" + days + "Day " + hours + "hour " + minutes + "minute " + seconds + "second"

 //script tag is not shown it is example








4.  when we run this scource code .this second will not update every second  so we need to update in every second  for this we will use of setInterval   in this block like :

  // setInterval(Function_name, time_in_millisecond)

            setInterval(myFunction1000)
      





5.  In the time i used if condition that if day == 0 so my time came in this case you can print any offer but i print Happy new years dears enjoy this days

  otherwise else="" . it is optional you can skip this code-source who i showen here


   //when days =0 in this case 1 january optional you can leave of this code-source
            if (days === 0) {
                document.getElementById('happy').innerText = 
"Happy new years dears enjoy this days";


    } 
else     // else nothing 
                document.getElementById('happy').innerText = "";
            }
/* -----*/


5.  And after closing of this block we need to call the our function

see this example :


function myFunction{


       
     }
        myFunction();

you can use of this source-code through copy and paste.

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding0px;
            margin0;
            box-sizingborder-box;
        }
        
        body {
            background-imageurl("domenico-loia-hGV2TfOh0ns-unsplash.jpg");
            background-positioncenter;
            background-sizecover;
            background-repeatno-repeat;
            height100vh;
        }
//css of box where countdownlist will show
        
        #demo {
            background-colorblack;
            colorwhite;
            background-colorblack;
            font-weightbold;
            font-size35px;
            width700px;
            positionabsolute;
            top35%;
            left50%;
            transformtranslate(-50%-50%);
            text-aligncenter;
            height180px;
            padding-top40px;
            border-radius30px;
            letter-spacing3px;
            opacity0.8;
            font-stretchultra-expanded;
        }
    </style>
</head>

<body>
    <p id="demo">
        <h5 id="happy"></h5>

    </p>
    <script>
        //here i created a object then get time in milliseconds from this date, check DOB

        var d = new Date("Jan 1,2021  00: 00:01");
        var final = d.getTime();
        var well = "2021 will coming soon";


        function myFunction() {



            //object for date present date
            var nowDate = new Date();
            // again i get time in milliseconds of present date
            var again = nowDate.getTime();


            // now different between "d" and "again"
            var different = final - again;


            // change of different in days 
            var days = Math.floor(different / (1000 * 60 * 60 * 24));
            // change of this different in hours
            var hours = Math.floor((different % (1000 * 60 * 60 * 24)) 
/ (1000 * 60 * 60));
            // change of this different in minutes
            var minutes = Math.floor((different % (1000 * 60 * 60)) / (1000 * 60));

            //change of this different in seconds
            var seconds = Math.floor((different % (1000 * 60)) / 1000);

            //here i am printing of this all days, hours , minutes, seconds

            document.getElementById("demo").innerHTML = well + "<br>" + days + "Day " + hours + "hour " + minutes + "minute " + seconds + "second";

            //when days =0 in this case 1 january optional you can leave of this code-source
            if (days === 0) {

                document.getElementById('happy').innerText = 
"Happy new years dears enjoy this days";

            } else {

                // else nothing 
                document.getElementById('happy').innerText = "";
            }
/* -----*/

            setInterval(myFunction1000)
        }
        myFunction();
    </script>
</body>

</html>

Comments

Popular posts from this blog

Top 10 Data Analysis Tools For Your Business with Review Rated

  Top 10 Data Analysis Tools For Your Business with   Review and Rated            Data analysis  is one of the most backbone of the any success business now a days . you can not predict a success business without data analysis.  indirect or direct every business involve in Data analysis.  every business organization  want to make his own approach in the whole market through this Data analysis .  Example : what will demand of any product in Future    according to previous selling product or on demand  products  that why every business organization or business needs Data analysis . Here we will see that top 10 ten Data analysis Tools for your any business and if you are student and you are  interest to learn Data analysis and you need any free data analysis tool for exercise so don't  worry you will get two free tools with download link at the last of this all tools in this web page . There are manly two methods of data analysis: Qualitative Analysis Quantitative Analysis Qualitative

Function in Python programming language

  Function in Python? In Python, a function is a group of related statements that performs a specific task. Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable. Furthermore, it avoids repetition and makes the code reusable. Syntax of Functio n def function_name ( parameters ): """ docstring """ statement(s) Above shown is a function definition that consists of the following components. Keyword  def  that marks the start of the function header. A function name to uniquely identify the function. Function naming follows the same rules of writing identifiers in Python. Parameters (arguments) through which we pass values to a function. They are optional. A colon (:) to mark the end of the function header. Optional documentation string (docstring) to describe what the function does. One or more valid python statements that make up the function body. Stateme

Glowing text in css

Glowing text in CSS Hello student in this tutorial we will see that how to make glowing text in css  so let's  break down this topic here . 1 . we taking a div or any tag, class, id for targeting text so here i am taking a id so first  we will center of this element through position absolute like this       #text  {              /* position center through position absolute*/              position :  absolute ;              top :  40 % ;              left :  50 % ;              transform :  translate ( -50 % ,  -50 % ); } 2. Again in this css we coding for text shadow like this through text-shadow carefully see of this code here and try in your code editer.             #text  {              /* position center through position absolute*/              position :  absolute ;              top :  40 % ;              left :  50 % ;              transform :  translate ( -50 % ,  -50 % );              /* text glowing like this pay attention here */              text-shadow :  0   0   4 px