At first I explain something I am implementing and technologies I use then I explain my problem.
I use node.js to implement API to get data from client and stores data to Mysql db. My server is ubuntu 16.04.2 and Mysql 5.7.18-0 and node 6.2.2; There is a table where the client data is stored at, and this table has a datetime
field.(My question is related to this field)
What I want: I get time in GMT and want to store and retrieve it in GMT too; My server time zone is -4:00;
I have two problems, here is what happens:
I get time in GMT from client and log received data;
{"clientId":10002,"frame":[{"location":{"lat":35.624658333333336,"lng":51.51242666666667},"time":"2017-06-03 23:38:56","speed":0}]}
The server log shows me this data is saved
But when I try to select record of this client in code by bookshelf, It seems the date is returned in server time zone;
I request to get data between times 2017-06-03 23:00:00
and 2017-06-03 23:59:00
and by there is no record!
and when I change the range of date to get records to something like 2017-06-03 15:00:00
and 2017-06-03 15:30:00
I get the 13 records; One of them is:
Query by sql:
+----------+-----------+---------------------+-------+
| latitude | longitude | date | speed |
+----------+-----------+---------------------+-------+
| 35.62494 | 51.507055 | 2017-06-03 15:00:25 | 16 |
+----------+-----------+---------------------+-------+
Query by bookshelf:
{latitude: "35.62494", longitude: "51.507055", date: "2017-06-03T19:00:25.000Z", speed: 16}
It seems the query by bookshelf returns date converted to server time, Is it possible at save time, date is converted to server time too? (related to missing record at time 2017-06-03 23:38:56
) (It is important to say there is no record between 2017-06-03 19:00:00
and 2017-06-03 19:59:00
)
How can I prevent bookshelf from converting date? I need to get time in GMT without any conversion.
via Fa.Shapouri
No comments:
Post a Comment