日付の取得
本日の日付の取得(0埋め)
$(function(){
let date = new Date();
let year = date.getFullYear();
let monthRow = date.getMonth() + 1;
let month = ('0'+monthRow).slice(-2);
let day = ('0'+date.getDate()).slice(-2);
let today = year+'-'+month+'-'+day;
$('セレクタ').val(today);
});
日付AのX日後を日付Bに表示(0埋め)
$('セレクタA').on("change",function(){
let date_A = $('セレクタA').val();
let dt = new Date(date_A);
// 各年月日の増減
dt.setFullYear(dt.getFullYear() + X年)
dt.setMonth(dt.getMonth() + Xか月);
dt.setDate(dt.getDate() + X日);
// 加減後の日付の取得
let year = dt.getFullYear();
let month = dt.getMonth() + 1;
let date = dt.getDate();
//0埋め
month = ('0'+month).slice(-2);
date = ('0'+date).slice(-2);
let today = year+'-'+month+'-'+date;
$('セレクタB').val(today);
});