简体   繁体   中英

Identify date format in jquery and set it as default in a jquery datepicker

// I have installmentDate which is an object object

var installmentDate = installment.installmentDate;                                     
alert(JSON.stringify(installmentDate));

Using JSON.stringify(installmentDate) it shows

{"date":3, "day":5, "hours":0, "minutes":0, "month":9, "nanos":0, "seconds":0, "time":1412274600000, "timezoneoffset":-330, "year":114}

Please identify in which format this is in. And I am trying to set this date as default to a jquery datepicker These are the following ways I tried and nothing works

$('#dueDate').datepicker('setDate', installmentDate);
$('#dueDate').datepicker('setDate', new Date((installment.installmentDate));
$('#dueDate').val(installmentDate);

Your date does not have the proper format. According to the documentation, here are the possible options:

The new date may be a Date object or a string in the current date format (eg, "01/26/2009"), a number of days from today (eg, +7) or a string of values and periods ("y" for years, "m" for months, "w" for weeks, "d" for days, eg, "+1m +7d"), or null to clear the selected date.

You might need to reformat your installmentDate .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM