Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Golang, MySQL connection does not set the time zone

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Package main

Import (

"fmt"

"github.com/go-xorm/xorm"

_ "github.com/jinzhu/gorm/dialects/mysql"

"time"

)

Func main () {

Engine, err: = xorm.NewEngine ("mysql", "root:password@/db_name?charset=utf8&loc=Local")

If erratic roomnil {

Fmt.Println (err)

Return

}

Engine1, err: = xorm.NewEngine ("mysql", "root:112358@/dhb_newdata_2?charset=utf8") if erratum nil {fmt.Println (err) return} var result stringnow: = time.Now () sql: = "SELECT DATE (?)" _, err=engine.SQL (sql, now). Get (& result) fmt.Println ("engine, with timezone", result,now) _, err=engine1.SQL (sql, now). Get (& result) fmt.Println ("engine1, no timezone", result,now)

}

Output result:

Engine, with timezone 2018-11-08 2018-11-0800: 36 CST 05.6461211 + 0800 Maxwell 0.016989801

Engine1, no timezone 2018-11-07 2018-11-0800: 36 CST 05.6461211 + 0800 Maxwell 0.016989801

You can see that using the DATE function in MySQL results in a missing day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report