react-calendar '일' 빼기

OwlSuri·2022년 5월 14일
5

react-calendar를 커스텀해야하는데
자꾸 거슬리는 것이

날짜 뒤에 있는 '일'

이것을 없애려고 검색해보니
formatDay locale이 ko라고 되어있으면 '일'이 나온다고 한다.
해결하기 위해서 formatDay에 사용된 locale을 en 으로 고정시키면 숫자만 나온다고 하는데,
ko를 찾지 못했다...

그래서
해결방법

import dayjs from 'dayjs';

를 한다음

Calendar부분 formatDay에

formatDay ={(locale, date) => dayjs(date).format('DD')}

이렇게 날짜만 나오게 하니까 된다!

아래는 전체코드

import React, { useState } from 'react';
import * as S from './calendar.styles'
import dayjs from 'dayjs';

export default function MiniCalendar(){

    const [value, onChange] = useState(new Date());
    
    return(
    <S.Wrapper>
      <S.MiniCalendar  onChange={onChange} value={value} 
      formatDay ={(locale, date) => dayjs(date).format('DD')}
      />
    </S.Wrapper>
    )
}

두번째 방법은 moment를 이용하기

yarn add moment

로 설치한 다음

import moment from 'moment';

import하고

formatDay={(locale, date) => moment(date).format("DD")}

dayjs 대신 moment를 써도 된다!

예뻐지고 있다😍

profile
기억이 안되면, 기록을 -

1개의 댓글

comment-user-thumbnail
2022년 9월 21일

ㅠ 감사합니다.

답글 달기