Created
March 22, 2016 03:26
-
-
Save shenli/240e447170383e4d59b9 to your computer and use it in GitHub Desktop.
MySQL Time test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"fmt" | |
_ "github.com/go-sql-driver/mysql" | |
"time" | |
) | |
func main() { | |
dsn := "root:@tcp(127.0.0.1:3306)/test?parseTime=True" | |
db, err := sql.Open("mysql", dsn) | |
_, err = db.Exec("drop table if exists t_time;") | |
if err != nil { | |
panic(err) | |
} | |
_, err = db.Exec("create table t_time (c Timestamp);") | |
if err != nil { | |
panic(err) | |
} | |
_, err = db.Exec("insert into t_time values (?);", time.Now()) | |
if err != nil { | |
panic(err) | |
} | |
row := db.QueryRow("select * from t_time;") | |
var c time.Time | |
row.Scan(&c) | |
fmt.Println(c) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment