moment.js
を使用してhours & minutes
の形式の2つの日付を追加しようとしています。しかし結果はinvalid
です。モーメントを使用して時間が分の場合は2回追加します.js
$(document).ready(function() {
$(".table-class").each(function() {
var total = 0;
$(this).find(".timeClass").each(function() {
var value = $(this).val();
var start = moment(value, 'h:mma');
console.log(start);
total += start;
});
$(".total").text(moment(total, 'h:mma'));
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table-class">
<tr>
<td>
<input type="text" value="1 hour 30 mins" class="timeClass">
</td>
</tr>
<tr>
<td>
<input type="text" value="3 hours 02 mins" class="timeClass">
</td>
</tr>
</table>
<p class="total">
</p>
任意の提案、ありがとうございください!
が助けをどうもありがとうございます:) – 06011991