package main import ( "fmt" "time" ) // @link https://golang.org/pkg/time/ func main() { //caution : format string is `2006-01-02 15:04:05.000000000` current := time.Now() fmt.Println("origin : ", current.String()) // origin : 2016-09-02 15:53:07.159994437 +0800 CST fmt.Println("mm-dd-yyyy : ", current.Format("01-02-2006")) // mm-dd-yyyy : 09-02-2016 fmt.Println("dd-mm-yyyy : ", current.Format("02-01-2006")) // dd-mm-yyyy : 02-09-2016 fmt.Println("yyyy-mm-dd : ", current.Format("2006-01-02")) // yyyy-mm-dd : 2016-09-02 // separated . fmt.Println("yyyy.mm.dd : ", current.Format("2006.01.02")) // yyyy.mm.dd : 2016.09.02 // separated / fmt.Println("yyyy/mm/dd : ", current.Format("2006/01/02")) // yyyy/mm/dd : 2016/09/02 fmt.Println("yyyy-mm-dd HH:mm:ss : ", current.Format("2006-01-02 15:04:05")) // yyyy-mm-dd HH:mm:ss : 2016-09-02 15:53:07 // StampMilli fmt.Println("yyyy-mm-dd HH:mm:ss: ", current.Format("2006-01-02 15:04:05.000")) // yyyy-mm-dd HH:mm:ss: 2016-09-02 15:53:07.159 // StampMicro fmt.Println("yyyy-mm-dd HH:mm:ss: ", current.Format("2006-01-02 15:04:05.000000")) // yyyy-mm-dd HH:mm:ss: 2016-09-02 15:53:07.159994 //StampNano fmt.Println("yyyy-mm-dd HH:mm:ss: ", current.Format("2006-01-02 15:04:05.000000000")) // yyyy-mm-dd HH:mm:ss: 2016-09-02 15:53:07.159994437 }