date - 在golang中解析大写字母月份
问题描述
我想解析"25-APR-2019"
字符串time.time
我知道使用解析日期
date, err := time.Parse(layout, stringVariableForDate)
但我在https://golang.org/pkg/time/#pkg-constants中没有找到布局选项
我不能使用 JAN,因为使用它,我收到错误:
panic: parsing time "25-APR-2019" as "02-JAN-2006": cannot parse "APR-2019" as "-JAN-"
如何在go-lang中解析带有大写字母月份名称的日期字符串?
解决方案
import "time"
可识别的月份格式为“Jan”和“January”。
解析布局缩写月份格式为“Jan”。使用“02-Jan-2006”作为解析布局。
例如,
package main
import (
"fmt"
"time"
)
func main() {
date, err := time.Parse("02-Jan-2006", "25-APR-2019")
fmt.Println(date, err)
}
游乐场: https: //play.golang.org/p/5MRpUrUVJt4
输出:
2019-04-25 00:00:00 +0000 UTC <nil>
推荐阅读
- python - 自回归模型的部分拟合或增量学习
- kubernetes - 无法连接到服务器:x509:证书对 ingress.local 有效,而不是 Rancher
- css - 带有 Angular11 文本的布尔玛没有改变,但背景会改变
- python - 如何消除 Python 中的多余内存?
- vuex - 谁能告诉我如何加速我的 vuejs 应用程序?
- java - Wildfly Thorntail 由于等待服务容器稳定的操作超时而无法部署
- c# - 通过 PUT 请求的正文发送图像
- flutter - Flutter RadioListTile 更改 Radio(icon) 颜色
- sql - 试图检查表中是否存在记录-Oracle sql
- pine-script - Pine Script 策略买入限价