Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current date using jquery?

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?

like image 958
RPB Avatar asked Jan 17 '11 05:01

RPB


People also ask

How can I get current date in YYYY MM DD format in 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!

How can get today day in jquery?

You can do it like that: var d = new Date(); var month = d. getMonth()+1; var day = d.

How do I get todays date in JavaScript?

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.


2 Answers

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());
like image 63
Naveed Avatar answered Nov 04 '22 10:11

Naveed


You can find the sample here.

<input type="text" id="datepicker">
$( "#datepicker" ).datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date());
like image 27
Arun P Johny Avatar answered Nov 04 '22 10:11

Arun P Johny