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 mutex 源码解析

分享5种文件变更时自动重载Go程序的方法

手撸Golang 基本数据结构与算法 冒泡排序

Golang两个协程交替输出

Go操作kafka

Go学习(第一天)

Golang怎么判断套接字是否关闭

Golang变量的数据类型

详解Golang中方法的receiver为指针和不为指针的区别

vim安装Go插件vim-GoGocode,支持代码高亮、代码提示和语法检查等功能

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




打赏

取消

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

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

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

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

评论

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