How to get current date using jquery?

I am using a calendar plugin and I want to fill in the current date in a text box. How to do it using jquery?

+6
jquery date jquery-plugins
source share
2 answers

You can get the current date in JavaScript :

var now = new Date(); 

If you are using jQuery DatePicker , you can apply it to any text field as follows:

 $('input.youTextFieldClass').datepicker({ dateFormat: 'mm/dd/yy', changeMonth: true, changeYear: true, yearRange: '-70:+10', constrainInput: false, duration: '', gotoCurrent: true}); 

If you want to set the current date in the text fields when loading the page:

 $("input.youTextFieldClass").datepicker('setDate', new Date()); 
+12
source share

Here you can find a sample.

 <input type="text" id="datepicker"> $( "#datepicker" ).datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date()); 
+2
source share

All Articles