-
Sequelize) createdAt의 timezone 설정MySQL 2022. 10. 29. 20:05
맡은 파트에서 상품의 주문시간을 노출시켜야 하는데, 널리 알려져있듯이 한국은 근대적 시간으로부터 변방으로 밀려나있다.
GMT 시간에 9시간을 더해야 한다.
문제는 타임존을 (timezone: "+09:00" ) 설정해 sequelize는 9시간을 더해 저장하더라도, 자바스크립트는 그 설정을 따르지 않는다는 것.
그러니까, 타임존 설정만 하면 저장(create)은 9시간을 더하여 되지만 읽어올 때(find)는 도로 GMT 시간이 된다.
이 문제를 정면돌파할 방법을 아직은 알지 못하지만, 우회로는 만들어낼 수 있었다.
- dateStrings:true로 시간을 그냥 문자열로 가져온다.
- typeCast: true 는 ISO8601 의 날짜를 (그냥 못생기게 나온다고 읽는다.) 깔끔하게 정리해준다.
- typeCast 적용 이전
- typeCast 적용 이후
//config.js require('dotenv').config(); module.exports = { development: { username: process.env.DB_USER, password: process.env.DB_PASSWORD, database: process.env.DB_NAME, host: process.env.DB_HOST, dialect: 'mysql', timezone: "+09:00", dialectOptions: { charset: 'utf8mb4', dateStrings: true, typeCast: true } }, test: { username: process.env.DB_USER, password: process.env.DB_PASSWORD, database: process.env.DB_NAME, host: process.env.DB_HOST, dialect: 'mysql', }, production: { username: 'root', password: null, database: 'database_production', host: '127.0.0.1', dialect: 'mysql', }, };
시간에 대해서는 여러 공부가 더 필요하다.
https://meetup.toast.com/posts/125
자바스크립트에서 타임존 다루기 (1) : NHN Cloud Meetup
자바스크립트에서 타임존 다루기(1)
meetup.toast.com
https://meetup.toast.com/posts/130
자바스크립트에서 타임존 다루기 (2) : NHN Cloud Meetup
자바스크립트에서 타임존 다루기 (2)
meetup.toast.com
https://en.wikipedia.org/wiki/ISO_8601
ISO 8601 - Wikipedia
From Wikipedia, the free encyclopedia Jump to navigation Jump to search International standards for dates and times Current date and time expressed according to ISO 8601 [refresh]Date2022-10-29Date and time in UTC2022-10-29T09:23:51+00:002022-10-29T09:23:5
en.wikipedia.org
https://velog.io/@hwang-eunji/sequelize-config-파일과-raw-옵션
sequelize config 파일과 raw 옵션
참고 사이트 : 시퀄라이즈 타임존 설정하기위 설정에서 dialectOptions, timezone를 보면 된다.타임존 설정 전 : 2018-10-18T06 : 45 : 38.000Z 요런 형태에서타임존 설정 후 : 2018-10-19 01:08:50 요런 형태로 한국
velog.io
https://devstudioonline.com/article/sequelize-set-timezone-and-datetime-format-for-mysql
Sequelize set timezone and datetime format for mysql
When you use Sequelize ORM to connect database then you might face issue time wrong time retrieval from the database. Because Sequelize returns UTC in select queries for DateTime fields. It this situation you need to change the configuration of Sequeliz
devstudioonline.com
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=varkiry05&logNo=221580851696
[nodejs-sequelize] timezone 적용, 조회시 시간 제대로 표기하기
sequelize 를 사용하면 DB에 저장시 자동으로 생성일, 수정일을 업데이트 해주는 기능이 있다. 그 옵션이...
blog.naver.com
'MySQL' 카테고리의 다른 글
MySQL index의 기록 (22.11~22.12 HospitAl Talk 프로젝트) (1) 2022.12.19 MySQL 튜닝의 기록 (22.11~12 HospitAI Talk 프로젝트) (0) 2022.12.19 SQL : group by, order by (0) 2022.10.09 SQL : 범위조건 between (0) 2022.10.09 SQL : 제외, 범위, 포함, 문자열패턴검색 in, like, distinct, limit, count (0) 2022.10.09