본문 바로가기
라이브러리 도구

[dayjs]빼기 더하기 하는 방법

by devebucks 2021. 10. 13.
728x90

dayjs 빼기

참고 : https://day.js.org/docs/en/manipulate/subtract

 

Day.js · 2kB JavaScript date utility library

2kB JavaScript date utility library

day.js.org

const day = '2021-08-01T00:00:00'
console.log(day);
const sStartTime = dayjs(day).subtract(1, 'day');

 

dayjs 더하기

참고 👉 https://day.js.org/docs/en/durations/add

const a = dayjs();
a.add(2, 'days');

 

dayjs format 설정

 

 

실 사용 코드

function __() {
    // this.chartOptions.scales.xAxis.min '2021-08-12T17:00:42';
    // this.chartOptions.scales.xAxis.max '2021-10-15T17:00:42';
    const sStartTime = dayjs(this.chartOptions.scales.xAxis.min).subtract(this.pIntervalInfo.value, this.pIntervalInfo.type).format('YYYY-MM-DDThh:mm:ss');
    const sEndTime = dayjs(this.chartOptions.scales.xAxis.max).add(this.pIntervalInfo.value, this.pIntervalInfo.type).format('YYYY-MM-DDThh:mm:ss');
    this.chartOptions.scales.xAxis.min = sStartTime; //'2021-08-11T17:00:42';
    this.chartOptions.scales.xAxis.max = sEndTime; //'2021-10-16T17:00:42';
}

 

728x90

댓글