I am using a calender plug-in and I want to populate the current date into a text field. How can I do this using jquery?
Your answer get current date in jquery in dd/mm/yyyy format” Code Answer. var mm = String(today. getMonth() + 1). padStart(2, '0'); //January is 0!
You can do it like that: var d = new Date(); var month = d. getMonth()+1; var day = d.
In JavaScript, we can easily get the current date or time by using the new Date() object. By default, it uses our browser's time zone and displays the date as a full text string, such as "Fri Jun 17 2022 10:54:59 GMT+0100 (British Summer Time)" that contains the current date, time, and time zone.
You can get current date in JavaScript:
var now = new Date();
If you are using jQuery DatePicker you can apply it on any textfield like this:
$('input.youTextFieldClass').datepicker({ dateFormat: 'mm/dd/yy',
changeMonth: true,
changeYear: true,
yearRange: '-70:+10',
constrainInput: false,
duration: '',
gotoCurrent: true});
If you want to set current date in textfields as page load:
$("input.youTextFieldClass").datepicker('setDate', new Date());
You can find the sample here.
<input type="text" id="datepicker">
$( "#datepicker" ).datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With