import (
"fmt"
"github.com/go-xorm/xorm"
_ "github.com/jinzhu/gorm/dialects/MysqL"
"time"
)
func main(){
ENGIne,err := xorm.NewENGIne("MysqL","root:[email protected]/db_name?charset=utf8&loc=Local")
if err!=nil{
fmt.Println(err)
return
}
ENGIne1,"root:[email protected]/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",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函数的时候导致少了一天