私は私が12 後に日付を入れてcalculation.If .Iはcode.Thisコードの下に年間のために完璧に働いていると年の年齢を計算することができますJSに非常に初心者です(例:14/12/1950)の今月のその月の表示NaN Years.Now私は年を表示したい年齢の誰から与えられた誕生日から。誰でもこれを手伝ってもらえますか?前もって感謝します。年齢、年月日をjs(js ui datepickerを使用)で計算する方法は?
$(document).ready(function()
{
console.log($(document).width());
$('#datepicker').datepicker
({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '1900:2150',
maxDate: new Date(),
inline: true,
onSelect: function() {
var birthDay = document.getElementById("datepicker").value;
var DOB = new Date(birthDay);
var today = new Date();
var age = today.getTime() - DOB.getTime();
age = Math.floor(age/(1000 * 60 * 60 * 24 * 365.25));
document.getElementById('agecal').innerText = age;
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="form-group">
<label for="datepicker">Date of Birth: <span style="color:red">*</span></label>
<input type="text" id="datepicker" name="date_of_birth" class="form-control" placeholder="Insert your Date of Birth...">
</div>
<div class="form-group">
<label for="agecal">Age as On(<?php echo date('d/m/Y'); ?>): <span id="agecal" style="background-color:#60ab59;padding: 0px 50px 0px 50px;color: white;font-weight: bold; border-radius: 5px;" >0</span></label>
</div>
私は2つの問題を持っていますが、これら二つの問題の答えを与えていません。 ** 1。**「年月日」のように年齢を欲しいです。 ** 2。** 12インチ(例えば1960年12月15日)の日付の後に 'NaN 'を表示します。 –
「12時以降」の問題の最新の回答。もう1つ(get monthなど)では、getMonthなどの関数を経過変数に使用してそのデータを取得できます。 – suvartheec