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

推荐订阅源

B
Blog RSS Feed
V2EX - 技术
V2EX - 技术
P
Privacy & Cybersecurity Law Blog
T
The Exploit Database - CXSecurity.com
美团技术团队
WordPress大学
WordPress大学
博客园 - 司徒正美
S
Securelist
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
Attack and Defense Labs
Attack and Defense Labs
Security Latest
Security Latest
L
LINUX DO - 最新话题
NISL@THU
NISL@THU
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Y
Y Combinator Blog
The Hacker News
The Hacker News
Security Archives - TechRepublic
Security Archives - TechRepublic
IT之家
IT之家
T
Threatpost
Hugging Face - Blog
Hugging Face - Blog
Scott Helme
Scott Helme
S
SegmentFault 最新的问题
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
小众软件
小众软件
V
Vulnerabilities – Threatpost
J
Java Code Geeks
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
博客园 - 【当耐特】
Microsoft Security Blog
Microsoft Security Blog
S
Security @ Cisco Blogs
雷峰网
雷峰网
Help Net Security
Help Net Security
The Last Watchdog
The Last Watchdog
Recent Announcements
Recent Announcements
G
Google Developers Blog
C
CERT Recently Published Vulnerability Notes
T
Troy Hunt's Blog
MyScale Blog
MyScale Blog

博客园 - 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

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