Describe the bug
Hi
prisma is very useful for me, but I have a problem about the timezone of datetime field.
I have no idea to change default timezone.
when insert data by prisma, createdAt and updatedAt field use UTC timezone datetime,
even if I have changed the mysql timezone to Asia/Shanghai
To Reproduce
type Config {
id: ID! @unique
code: String
name: String
value: Float
createdAt: DateTime!
updatedAt: DateTime!
}
$ docker exec deploy_db_1 date
Fri Aug 31 10:03:19 CST 2018
mutation {
createConfig(data: { code: "sxx", name: "xxx", value: 0.9 }) {
id
updatedAt
createdAt
}
}
json response:
{
"data": {
"createConfig": {
"id": "cjlhcteh700060b78hvce6zgf",
"updatedAt": "2018-08-31T02:03:19.053Z",
"createdAt": "2018-08-31T02:03:19.053Z"
}
}
}
Expected behavior
I expect json response will be:
{
"data": {
"createConfig": {
"id": "cjlhcteh700060b78hvce6zgf",
"updatedAt": "2018-08-31T10:03:19.053Z",
"createdAt": "2018-08-31T10:03:19.053Z"
}
}
}
Versions (please complete the following information):
prisma CLI: prisma/1.15.1 (linux-x64) node-v8.11.4]1.15.1graphql-cli : 2.16.5, prisma-binding: 2.1.4graphql-yoga: 1.16.1I am having the same situation.
But I discovered that Prisma uses the UTC time explicitly (that is, for example, in: 2018-08-31T02:03:19.053Z the 'Z' indicates that the timezone is UTC).
So I can use a time manipulation library like Moment to convert to local time without any problems.
Please devs, you should consider adding this to the documentation. (if it isn't already).
Anyway, I wrote a guide below to change the timezone inside the docker containers. This should also be interesting to put in the Prisma docs.
I tried configuring both docker containers (one is for mysql, the other one for the Prisma server):
#Get the ID of the mysql container
docker container ls
docker exec -it {MYSQL_CONTAINER_ID} bash
sudo echo "Asia/Shanghai" > /etc/timezone
sudo dpkg-reconfigure -f noninteractive tzdata
#check if the time is set correctly
date
mysql -uroot -pprisma
Inside MySQL, run the queries below in order to verify if timezone is set correctly.
SELECT NOW();
SELECT @@global.time_zone, @@session.time_zone;
The timezone should be "SYSTEM", that is, configured by the system and not by mysql.
docker container ls
docker exec -it {PRISMA_CONTAINER_ID} bash
Then follow this tutorial for changing the timezone (the prisma container is based on Alpine Linux):
https://wiki.alpinelinux.org/wiki/Setting_the_timezone
Still, the createdAt and updatedAt fields are set according to UTC time, not the local time.
BTW, please change "is not work" to "doesn't work" 馃槈
I have changed the title , thank you for your reply! @stefanfuchs : )
I will follow your advice to use a time manipulation library like Moment to convert to local time.
thanks again about your detail advice!
Most helpful comment
BTW, please change "is not work" to "doesn't work" 馃槈