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 err!=nil{
fmt.Println(err)
return
}
engine1, err := xorm.NewEngine("mysql", "root:112358@/dhb_newdata_2?charset=utf8")
if err!=nil{
fmt.Println(err)
return
}
var result string
now := 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)
}
输出的结果:
engine, with timezone 2018-11-08 2018-11-08 00:36:05.6461211 +0800 CST m=+0.016989801
engine1, no timezone 2018-11-07 2018-11-08 00:36:05.6461211 +0800 CST m=+0.016989801
可以看到在MySQL里使用DATE函数的时候导致少了一天
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。