Go编程基础 : 时间格式字符串

package main

import (
	"fmt"
	"time"
)

// 来自github.com\mattn\[email protected]\sqlite3.go
var SQLiteTimestampFormats = []string{
	// By default, store timestamps with whatever timezone they come with.
	// When parsed, they will be returned with the same timezone.
	"2006-01-02 15:04:05.999999999-07:00",
	"2006-01-02T15:04:05.999999999-07:00",
	"2006-01-02 15:04:05.999999999",
	"2006-01-02T15:04:05.999999999",
	"2006-01-02 15:04:05",
	"2006-01-02T15:04:05",
	"2006-01-02 15:04",
	"2006-01-02T15:04",
	"2006-01-02",
}


func main()  {
	var now = time.Now()
	for _, tf := range SQLiteTimestampFormats {
		fmt.Println("Format: ", tf, "; Now: ", now.Format(tf))
	}
/*
Format:  2006-01-02 15:04:05.999999999-07:00 ; Now:  2020-07-06 21:33:43.8045583+08:00
Format:  2006-01-02T15:04:05.999999999-07:00 ; Now:  2020-07-06T21:33:43.8045583+08:00
Format:  2006-01-02 15:04:05.999999999 ; Now:  2020-07-06 21:33:43.8045583
Format:  2006-01-02T15:04:05.999999999 ; Now:  2020-07-06T21:33:43.8045583
Format:  2006-01-02 15:04:05 ; Now:  2020-07-06 21:33:43
Format:  2006-01-02T15:04:05 ; Now:  2020-07-06T21:33:43
Format:  2006-01-02 15:04 ; Now:  2020-07-06 21:33
Format:  2006-01-02T15:04 ; Now:  2020-07-06T21:33
Format:  2006-01-02 ; Now:  2020-07-06
*/
}

猜你喜欢

转载自blog.csdn.net/halo_hsuh/article/details/106916360