codestates / codestates/Subllet
[ERR] new Date()
Open
ERR
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
### 어떤 에러인가요?
- new Date()로 현재 시간을 할당하고 slice를 사용하여 잘라 사용하려 했지만 에러가 났다.
### 에러 메시지
```shell
TypeError: date.slice is not a function
```
### 에러 핸들링 방법
- new Date()를 할당하면 객체 타입으로 나오는지 몰랐다.. 그래서 toString을 이용하여 문자열로 변경후 사용하였지만 추가적으로 찾아보니 변경하는 방법이 몇가지 더 있었다!!
```js
toString() - 'Tue Dec 14 2021 01:58:19 GMT+0900 (한국 표준시)'
toDateString() - 'Tue Dec 14 2021'
toLocaleString() - '2021. 12. 14. 오전 1:58:19'
toLocaleDateString() - 2021. 12. 14.'
```
### 에러 핸들링을 위해 참고한 레퍼런스 링크
https://dororongju.tistory.com/116
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.