0
我正在使用日期選擇器來選擇出生日期。 我有三個輸入框。 輸入後31/08/1991
出生日期自動計算年月和日像21 year
1 months
2 Days
。如何從出生日期獲得年月日
$(function() {
$("#dob").datepicker({
changeMonth : true,
changeYear : true,
defaultDate: '-30yr',
yearRange: 'c-25:c+35',
onSelect: function(selectedDate) {
var a = $("#dob").datepicker("getDate");
var today = new Date();
var age = Math.floor((today-a)/(24 * 60 * 60 * 1000));
var year = Math.round(age/365);
var month = Math.round(age/30);
$('#ages').val(year);
}
});
$("#dob").datepicker("option", "dateFormat", 'dd-mm-yy');
$("input:submit, a, button", ".registerSubmit").button();
});