All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

JavaScript Date Format dd/mm/yyyy

Last Updated : Jul 1, 2023

JavaScript Date Format dd/mm/yyyy

In this article we will show you the solution of JavaScript date format dd/mm/yyyy, there is various way to convert date to string.

In this tutorial,we are going to use the getDate(), getMonth(), and getFullYear() methods to get the date format to dd/mm/yyyy format.

Date(): by using the function in JavaScript converts the timestamp with a date format.

Step By Step Guide On JavaScript Date Format dd/mm/yyyy :-

<!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> JavaScript date format dd/mm/yyyy </title>
    <style>
        body {
            font-family : 'Lucida Sans', Verdana , sans-serif ;
        }
        h1 {
         font-size : larger ;
         font-weight : bolder ;
         color : rgb(113, 221, 113) ;
         text-align : center ;
        }
        h3 {
            text-align : center ;
        }
    </style>
</head>
<body>
    <h1> TALKERSCODE </h1>
    <h3> JavaScript date format dd/mm/yyyy </h3>
    <p id = "result"></p>
    <script>
        var d = new Date () ;
        var date = d.getDate () ;
        var month = d.getMonth () + 1 ;
        var year = d.getFullYear () ;
        var final_date = date + '/' + month + '/' + year ;
        document.getElementById ("result").innerHTML = final_date ;
    </script>
</body>
</html>
  1. First, we write <! DOCTYPE html> which we used as the instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As mentioned above, the <head> tag contains information about the web page. In this tag, a <title> tag is used which helps us to specify a webpage title.
  4. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  5. Now create a < style > tag to add style to the HTML page.
  6. Thirdly, the <body> tag is used to define the webpage body. All the contents to show on the website are written here.
  7. <h1> tag used to add heading here.
  8. <p> tag with the id ‘result used here to display the result.
  9. Now create a <script> tag to write the JavaScript file. And close it with </script> tag.
  10. Create a variable ‘d’ to hold the new Date () object.
  11. Create variables to get the date, month, and year with getDate (), getMonth (), and getFullYear () functions.
  12. Finally created final_date variable for a date in dd/mm/yyyy format
  13. Document.getElementById() to display the final date into the HTML page by the <p> tag

Conclusion :-

At last, here in conclusion, here we can say that with this article’s help, we know how to date format dd/mm/yyyy using JavaScript.

I hope this article on JavaScript date format dd/mm/yyyy helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Anjali

Experienced Computer Programmer with a broad range of experience in technology. Strengths in application development and Object Oriented architecture design, front end programming, usability and multimedia technology. Expert in coding languages such as C, C++ Java, JavaScript, PHP and more.

Follow Anjali On Linkedin 🡪