This is a creation in Article, where the information may have evolved or changed.
Today is the second time to jump into this hole.
The interface I'm going to have is a requirement to filter out unfinished and outdated content based on the set start time and end time. I use it xorm as an ORM engine for database development. A direct one solves the problem. It was a bit of a test, and there was no problem.
Where("displayorder<>0 AND effectivetime< ? AND expirationtime> ?", time.Now(), time.Now())
Today iOS development wants to invoke my interface development, because I write the test data is incomplete, he called the test with a few test data. Test sister very professional, add an expired, a to show, a not started, and then I did not show the three article ...
After the problem was reported to me, it was clear that there was a problem. It must be that where the query was wrong. Xorm supports logging of SQL statements, which I have configured in the first development. Take a decisive look at the log. Copy SQL to navicat inside to run, found no problem ... This is evil. The solution is not to be baffled. I just started guessing. is not the time passed in. Now () there is a problem. I just formatted the date, I can.
const DATE_LAYOUT = "2006-01-02 15:04:05"now := time.Now()now_str := now.Format(DATE_LAYOUT)
This time fluke makes me feel very wrong (my intuition is still very accurate!!!) ), and then went to consult my omnipotent eldest brother, he said it should be UTC problem. It means the time zone, and I realized that I had stepped on the pit before. Add the time zone information to the MySQL connection string.
parseTime=true&loc=Asia%2FChongqing
Finally, my omnipotent eldest brother also told me that there is no need to pass the time in, directly using the MySQL function NOW() can be. Well, Big Brother is Big brother ...
Where("displayorder<>0 AND effectivetime< NOW() AND expirationtime> NOW()")
The Ruby team in my group is said to be a very good Ruby team in the country because the main station has been developed with Ruby. Our team only 5 people, the use of Golang as the main development language, Golang and relatively new, our team will become more than the domestic Golang team? Ha ha haha
Original link: Database access time zone issues, reproduced please indicate the source!