Golang Time Format Strings


本文摘自网络,作者,侵删。


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"


关于作者

http://www.real007.cn/about

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


本文来自:简书

感谢作者:大地缸

查看原文:Golang Time Format Strings

相关阅读 >>

Go语言基础之结构体

Go语言如何删除切片元素

[Go]解决Go-smtp发送内容乱码和发送html邮件不解析

Go 为什么这么“快”

Go语言 if 语句

Golang 上传office文档并转化为pdf

Golang网络数据传输过程中的binary.read与unsafe.pointer指针强转分析

Golang sqlx捕捉错误

Golang如何定义error

Go从学会到学废】(零) Golang简介

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...