nobel6018 / utterances

0 stars 0 forks source link

39f74376-46ed-4e38-bb35-b1980f5d4a31 #3

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

NestJS에서 DB + System + NestJS Timezone 처리 방법

NestJS에서 DB에서 불러온 데이터의 타임존을 어떻게 처리하는 지 궁금했습니다.

https://v3.leedo.me/39f74376-46ed-4e38-bb35-b1980f5d4a31

hongdor commented 2 years ago

매우 도움이 되었습니다. 감사합니다.

nobel6018 commented 2 years ago

도움이 되셨다니 뿌듯하네요!! 감사합니다 😃

majaeseong commented 1 year ago

좋은 글 감사합니다! 그렇다면 new Date()의 타임존을 변경하고 싶을때는 어떻게 하나요??

nobel6018 commented 1 year ago

댓글을 지금 확인했습니다 늦은 댓글 죄송합니다 ㅠㅠ

Node의 타임존은 process.env.TZ을 따라갑니다. 간단히 터미널에서 코드로 확인해보면

> process.env.TZ = 'UTC'
'UTC'
> new Date().toString()
'Mon Oct 31 2022 09:39:00 GMT+0000 (Coordinated Universal Time)'
> process.env.TZ = 'Asia/Seoul'
'Asia/Seoul'
> new Date().toString()
'Mon Oct 31 2022 18:39:42 GMT+0900 (Korean Standard Time)'

추가로 Docker 파일에서는 다음과 같이 Timezone을 설정하면 됩니다.

FROM node:18-alpine3.15

ENV TZ Asia/Seoul

도움이 되시면 좋겠습니다. 좋은 질문 감사합니다!! 👍