* data(json)
[
{
"id": "0",
"title": "경력 1",
"startDate": "2023-02-01 00:00:00",
"endDate": "2023-12-31 00:00:00
},
{
"id": "1",
"title": "경력 2",
"startDate": "2024-01-09 00:00:00",
"endDate": null,
}
]
* 계산식(js)
careerDate() {
if (!this.career) {
return;
}
const result = {
year: 0,
month: 0,
};
let diffMonth = 0;
this.career?.map(item => {
const startDate = dayjs(item.startDate);
const endDate = item.endDate ? dayjs(item.endDate) : dayjs();
diffMonth += endDate.diff(startDate, 'month', true);
});
result.year = Math.floor(diffMonth / 12);
result.month = Math.floor(diffMonth % 12);
return result;
}
* 화면(Vue.js)
<div class="box_head">
경력 총 {{careerDate.year}}년 {{careerDate.month}}개월
</div>