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

相关阅读 >>

Golang和Go是一样的吗

Go - time.rfc3339 时间格式化

利用Go实现快看漫画网页版自动点击“下一话”,中间无需手动操作,但有一点疑惑,望大佬们解答。

Golang命令Go env

Go fileserver

Golang有类(class)吗?

Golang面向对象编程之继承&虚基类【组合&接口】

如何读取yaml,json,ini等配置文件【Golang 入门系列九】

聊聊storagetapper的server

在使用database/sql时应避免掉进这11个坑 !(Go 数据库)

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




打赏

取消

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

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

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

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

评论

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