title: "Golang Time Format Strings"
date: 2021-02-01T20:50:52+08:00
draft: true
tags: ['go','time']
author: "dadigang"
author_cn: "大地缸"
personal: "http://www.real007.cn"
关于作者
package main
import (
"fmt"
"time"
)
// 来自github.com\mattn\go-sqlite3@v1.14.0\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",
"2006年01月02日",
"20060102",
}
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
*/
}
outputs
go run .
Format: 2006-01-02 15:04:05.999999999-07:00 ; Now: 2021-02-01 20:51:34.624336328+08:00
Format: 2006-01-02T15:04:05.999999999-07:00 ; Now: 2021-02-01T20:51:34.624336328+08:00
Format: 2006-01-02 15:04:05.999999999 ; Now: 2021-02-01 20:51:34.624336328
Format: 2006-01-02T15:04:05.999999999 ; Now: 2021-02-01T20:51:34.624336328
Format: 2006-01-02 15:04:05 ; Now: 2021-02-01 20:51:34
Format: 2006-01-02T15:04:05 ; Now: 2021-02-01T20:51:34
Format: 2006-01-02 15:04 ; Now: 2021-02-01 20:51
Format: 2006-01-02T15:04 ; Now: 2021-02-01T20:51
Format: 2006-01-02 ; Now: 2021-02-01
Format: 2006年01月02日 ; Now: 2021年02月01日
Format: 20060102 ; Now: 20210201
有疑问加站长微信联系(非本文作者)