How to format current date in MM/DD/YYYY HH:MM:SS format using JavaScript ? Last Updated : 30 Dec, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a date and the task is to format the current date in MM/DD/YYYY HH:MM:SS format. Here are a few of the most techniques discussed with the help of JavaScript. Approach 1: Store the current date in variable.Use the string concatenation technique to insert / and : in between the month-day and day-year.Use .slice() method to format the day, month to 2 digits. Example: This example implements the above approach. html <body> <h1 style="color:green;"> GeeksforGeeks </h1> <p id="GFG_UP"> </p> <button onclick="gfg_Run()"> Click Here </button> <p id="GFG_DOWN"> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var date = new Date(); el_up.innerHTML = "Click on the button to format" + " the date accordingly.<br>Date = " + date; function gfg_Run() { var Str = ("00" + (date.getMonth() + 1)).slice(-2) + "/" + ("00" + date.getDate()).slice(-2) + "/" + date.getFullYear() + " " + ("00" + date.getHours()).slice(-2) + ":" + ("00" + date.getMinutes()).slice(-2) + ":" + ("00" + date.getSeconds()).slice(-2); el_down.innerHTML = Str; } </script> </body> Output: Approach 2: Store the current date in a variable.Use the .join() method to insert / and : in between the month-day and day-year.Create a prototype padding to format the day, and month into 2 digits. Example: This example implements the above approach. html <body> <h1 style="color:green;"> GeeksforGeeks </h1> <p id="GFG_UP"> </p> <button onclick="gfg_Run()"> Click Here </button> <p id="GFG_DOWN"> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var d = new Date(); el_up.innerHTML = "Click on the button to format" + " the date accordingly.<br>Date = " + d; Number.prototype.padding = function(base, chr) { var len = (String(base || 10).length - String(this).length) + 1; return len > 0 ? new Array(len).join(chr || '0') + this : this; } function gfg_Run() { str = [(d.getMonth()+1).padding(), d.getDate().padding(), d.getFullYear()].join('/') + ' ' + [ d.getHours().padding(), d.getMinutes().padding(), d.getSeconds().padding()].join(':'); el_down.innerHTML = str; } </script> </body> Output: Comment More infoAdvertise with us Next Article How to format current date in MM/DD/YYYY HH:MM:SS format using JavaScript ? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-date JavaScript-Questions Similar Reads How to format the current date in MM/DD/YYYY HH:MM:SS format using Node? The current date can be formatted by using Nodejs modules like Date Object or libraries like moment.js. Table of Content Using Node.js Date ObjectUsing Moment.js LibraryMethod 1: Using Node.js Date Object:The JavaScript Date Object can be used in the program by using the following command. const dat 3 min read How to Get Current Formatted Date dd/mm/yyyy in JavaScript? Here are different ways to get the current date in dd/mm/yyyy format.1. Using Native JavaScript MethodsJavaScript's built-in Date object provides various methods to work with dates and times. You can extract individual components like day, month, and year to format the date manually.JavaScript// Get 2 min read How to extract date from a string in dd-mmm-yyyy format in JavaScript ? In this article, we will see how to extract date from a given string of format "dd-mmm-yyyy" in JavaScript. We have a string, and we want to extract the date format "dd-mmm-yyyy" from the string.Example:// Stringstr = "India got freedom on 15-Aug-1947"// Extracted date from given string in // "dd-mm 2 min read How To Format JavaScript Date as yyyy-mm-dd? We use JavaScript built-in help methods from the Date class that help us to create a formatted version of the current date in the form of yyyy-mm-dd. These are the approaches used to format JavaScript date as yyyy-mm-dd.Table of ContentUsing the ISO String Method USing JavaScript Method1. Using the 2 min read How to Format Datetime to YYYY-MM-DD HH:MM:SS in Moment.js? In Moment.js, formatting the date in the proper format is important for consistent data presentation and manipulation. The library provides various methods to handle and transform dates. You can use direct formatting with format(), manipulate ISO strings, or work with Unix timestamps to achieve the 2 min read Like