Get the App
SLTechnology News&Howtos  ›  Servers  › 

Golang, MySQL connection does not set the time zone

Shulou Source: shulou.com Published: 2022-06-03 00:30:42 11月15日 Update

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.

Tags: Function time result output time zone problem Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Apple MySQL MariaDB