Comments (11)
cmd/time.go中calculateTimeCmd的space=1的分支layout格式没有秒
from go-programming-tour-book-comments.
1.3.3.2 time calc 子命令
中,利用冒号:
来做分隔符会更妥当,使用空格作为分隔符会造成bug
from go-programming-tour-book-comments.
我直接clone下来项目但是测试的时候总是会有异常,输出结果: 1970-01-01 08:05, 300,一直报的是这个
from go-programming-tour-book-comments.
space := strings.Count(calculateTime, " ")中把" "改成" "就可以了
from go-programming-tour-book-comments.
改成":"
from go-programming-tour-book-comments.
好的,我按照你说的将空格删掉了之后就成功了,谢谢!
from go-programming-tour-book-comments.
输出异常的真正原因是,space为1的时候,layout写错了。
作者写成了layout = "2006-01-02 15:04"
,正确写法应该是layout = "2006-01-02 15:04:05"
from go-programming-tour-book-comments.
您好 1.3.3.2 time calc 子命令 处好像有bug
if space == 0 {
layout = "2006-01-02"
}
if space == 1 {
layout = "2006-01-02 15:04"
}
命令行中 2029-09-04 12:02:33 输入的space为1,但是匹配到的layout是 2006-01-02 15:04,在秒数上是对应不上的,因此会出现得出的结果为:1970-01-01 08:05。 按照代码贴上去发现了这个问题
from go-programming-tour-book-comments.
space := strings.Count(calcTime, " ")
if space == 0 {
layout = "2006-01-02"
}
if space == 1 {
layout = "2006-01-02 15:04"
}
如果输入时候多输入了空格会发生不可预测的问题,判断冒号":"可能会更好一些
from go-programming-tour-book-comments.
space := strings.Count(calculateTime, " ")
if space == 0 {
layout = "2006-01-02"
} else if space == 1 {
switch strings.Count(calculateTime, ":") {
case 0:
layout = "2006-01-02 15"
case 1:
layout = "2006-01-02 15:04"
}
}
from go-programming-tour-book-comments.
我觉得这样判断更合理,空格数量决定年月日后面有没有跟上时分秒,冒号数量决定时分秒这三个字段输入了几个:
space := strings.Count(calculateTime, " ")
if space == 0 {
layout = "2006-01-02"
} else {
switch strings.Count(calculateTime, ":") {
case 0:
layout = "2006-01-02 15"
case 1:
layout = "2006-01-02 15:04"
}
}
from go-programming-tour-book-comments.
Related Issues (20)
- 开启博客之路 | Go 语言编程之旅 HOT 5
- Go 大杀器之性能剖析 PProf(下) | Go 语言编程之旅 HOT 2
- gRPC 的使用和了解 | Go 语言编程之旅 HOT 5
- 同时提供 HTTP 接口 | Go 语言编程之旅 HOT 2
- Go 大杀器之性能剖析 PProf(上) | Go 语言编程之旅 HOT 6
- 基于 TCP 的聊天室 | Go 语言编程之旅 HOT 5
- 生成接口文档 | Go 语言编程之旅 HOT 13
- 缓存淘汰算法 | Go 语言编程之旅 HOT 1
- 缓存的性能和优化思路 | Go 语言编程之旅 HOT 2
- 进行项目设计 | Go 语言编程之旅 HOT 3
- 非核心功能 | Go 语言编程之旅 HOT 2
- 公开和发布度量指标 | Go 语言编程之旅 HOT 1
- gorm v2版本没有gorm解决方案
- 实现聊天室:广播器 | Go 语言编程之旅 HOT 3
- 附录 D:让 Go panic 的十种方法 | Go 语言编程之旅 HOT 2
- 服务注册和发现 | Go 语言编程之旅 HOT 1
- 用 GODEBUG 看调度跟踪 | Go 语言编程之旅 HOT 1
- 附录 B:Goroutine 与 panic、recover 的小问题 | Go 语言编程之旅 HOT 2
- WebSocket 介绍、握手协议和细节 | Go 语言编程之旅 HOT 13
- 在尝试blog-service中Logger部分出错
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-programming-tour-book-comments.