Method 1: Using toLocaleDateString() method: The toLocaleDateString() method is used to return a language sensitive representation of the date part of a Date object as a String. It has two optional parameters, locales and options. The locales parameter can be specified with language tags that are used to display the date according to the format of that locale. The locale has various options that can be used to modify the locale used.
The date can be formatted as ‘dd/mm/yyyy’ by specifying the locale as ‘en-GB’ which sets the locale to ‘British English’.
The date can be set to an input using the valueAsDate property. This property takes in a Date object to be displayed in the date selector by default. The current date can be shown by assigning it a new Date() object.
Syntax:
new Date().toLocaleDateString('en-GB')
Example:
<!DOCTYPE html> <html> <head> <title> How to get current formatted date dd/mm/yyyy in Javascript and append it to an input? </title> </head> <body> <h1 style="color: green"> GeeksforGeeks </h1> <b> How to get current formatted date dd/mm/yyyy in Javascript and append it to an input? </b> <p> Current Date is: <span class="currDate"></span> </p> <p> Please select the date to start the course: <input type="date" id="dateInput"> </p> <script type="text/javascript"> let currDate = new Date().toLocaleDateString('en-GB'); let inputDate = new Date(); document.querySelector('.currDate').textContent = currDate; document.querySelector('#dateInput').valueAsDate = inputDate; </script> </body> </html> |
Output:

Method 2: Splicing the string from the toLocalISOString() method: The date can be extracted from the string returned by the toLocalISOString() method. The string returned is sliced from 0 to 10th index by using slice(0, 10), split into separate components by the dash(-) separator, reversed to make the day value first, and then joined back using slash(/) as the separator. This gives the date in the ‘dd/mm/yyyy’ format.
The date can be set to an input using the valueAsDate property. This property takes in a Date object to be displayed in the date selector by default. The current date can be shown by assigning it a new Date() object.
Syntax:
new Date().toISOString().slice(0, 10).split('-').reverse().join('/')
Example:
<!DOCTYPE html> <html> <head> <title> How to get current formatted date dd/mm/yyyy in Javascript and append it to an input? </title> </head> <body> <h1 style="color: green"> GeeksforGeeks </h1> <b> How to get current formatted date dd/mm/yyyy in Javascript and append it to an input? </b> <p> Current Date is: <span class="currDate"></span> </p> <p> Please select the date to start the course: <input type="date" id="dateInput"> </p> <script type="text/javascript"> let currDate = new Date().toISOString().slice(0, 10) .split('-').reverse().join('/'); let inputDate = new Date(); document.querySelector('.currDate').textContent = currDate; document.querySelector('#dateInput').valueAsDate = inputDate; </script> </body> </html> |
Output:

Recommended Posts:
- How to get current formatted date dd/mm/yyyy in JavaScript ?
- How to validate if input date (end date) in input field must be after a given date (start date) using express-validator ?
- How to validate if input date (start date) in input field must be before a given date (end date) using express-validator ?
- How to get the first and last date of current month using JavaScript ?
- How to get the current date in JavaScript ?
- How to check the input date is equal to today's date or not using JavaScript ?
- How to get the current date and time in seconds?
- How to Get Current Date and Time in Various Format in Golang?
- How to format current date in MM/DD/YYYY HH:MM:SS format using JavaScript ?
- Getting the current date and time with timestamp in local and other timezones in Golang
- How to get the current URL using JavaScript ?
- How to get the current year using JavaScript ?
- How to validate if input in input field is a valid date using express-validator ?
- How to convert UTC date time into local date time using JavaScript ?
- How to get Month and Date of JavaScript in two digit format ?
- How to get the size of screen, current web page and browser window using jQuery?
- JavaScript | Get Date Methods
- How to get the month name from Date using JavaScript ?
- How to get current function name in PHP?
- Get the current URL using jQuery?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


