惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
Blog — PlanetScale
Blog — PlanetScale
阮一峰的网络日志
阮一峰的网络日志
Microsoft Azure Blog
Microsoft Azure Blog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
Y
Y Combinator Blog
D
DataBreaches.Net
Engineering at Meta
Engineering at Meta
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements

博客园 - forrestsun

问题整理 weedfs getsockopt: connection timed out 利用cubieboard设置samba打印服务器 CubieTruck上安装mjpg_streamer devexpress bandgridview使用总结(14.2) WeedFS0.6.8-引用库列表 NSQ的消息订阅发布测试 WeedFS问题收集 WeedFS依赖库 0.6.1 golang 前置补0 MongoDB-MMS使用总结 golang 格式化时间为字符串 mgo-后续测试(指定字段,获取id) mgo中DBRef-数据查询测试 mgo中DBRef-数据添加测试 weed-fs 基础测试 weed-fs 压力测试 weed-fs参数列表 mgo like的两种写法
格式化字符串为时间学习总结
forrestsun · 2014-01-26 · via 博客园 - forrestsun
package main

import (
	"fmt"
	"time"
)

func main() {
	test, err := time.Parse("2006-01-02", "2013-01-12")
	if err != nil {
		panic(err)
	}

	fmt.Println(test)
}
[ `run` | done: 4.533945ms ]
2013-01-12 00:00:00 +0000 UTC

其中time.parse格式改变后,未发生变化

test, err := time.Parse("2006/01/02", "2013/01/12")
[ `run` | done: 1.499388ms ]
2013-01-12 00:00:00 +0000 UTC

再换,结果未变:

test, err := time.Parse("01/02/2006", "01/12/2013")
[ `run` | done: 1.471152ms ]
2013-01-12 00:00:00 +0000 UTC

截取取小时:

test, err := time.Parse("2006-01-02 15", "2013-05-13 13")

截取到分钟:

test, err := time.Parse("2006-01-02 15:04", "2013-05-13 10:30")
[ `run` | done: 1.414665ms ]
2013-05-13 10:30:00 +0000 UTC

截取到秒:

 
test, err := time.Parse("2006-01-02 15:04:05", "2013-05-13 10:30:03")
[ `run` | done: 1.554238ms ]
2013-05-13 10:30:03 +0000 UTC

随着截取位置的不同,通过补零设置