antd table에 date 넣기

유진·2023년 11월 9일

231109(목)



해당하는 년도와 월을 넣고 싶다.

  // 년, 월
  const today = new Date();
  const year = `${(today.getFullYear()).toString()}년 누계`
  const month = `${(today.getMonth() + 1).toString()}월`

변수로 선언을 해주고
월은 +1을 꼭 해야한다. 그렇지 않으면 0월부터 시작이다.

 {
      title: year,
      children: [
        {
          title: '목표',
          dataIndex: 'CUMULRESULT',
          key: 'CUMULRESULT',
          width: 55,
          align: 'center',
          render: (text, record, index) =>
          ({
            children: text,
            props: {
              className: styles.noPadding,
              style: {
                padding: "12px", textAlign: "center", color: isDark ? '#fff' : "#122610"
              }
            },
          }),
        },
      }

title: year 넣으면 위에 먼저 선언한 변수를 가지고 온다.


여기서 오류가 났었는데,

today.getFullyear is not a function
TypeError: today.getFullyear is not a function

 const year = `${(today.getFullyear()).toString()}년 누계`
 ->
  const year = `${(today.getFullYear()).toString()}년 누계`

getFullyear Year를 대문자로 써야한다.

profile
긍정 🍋🌻

0개의 댓글