2017-06-17 61 views
-5

我有一个字符串,它是:将字符串转换日期(月,年)到了time.time

str := "Jan 2020" 

我需要将此转换为go.How了time.time格式可我做到这一点吗?

+1

也许这些人会帮助? https://stackoverflow.com/questions/25845172/parsing-date-string-in-golang,https://stackoverflow.com/questions/40388246/convert-string-to-time-and-parse-in-golang –

+0

我得到thi errro解析时间“2020年1月”为“2006-01-02T15:04:05Z07:00”:can not parse“Jan 2020”as“2006” 0001-01-01 00:00:00 +0000 UTC – rahul

+0

你的代码在哪里? – Flimzy

回答

2

@rahul你需要不断的布局格式字符串像你想解析,看看代码字符串:

package main 

import (
    "time" 
    "fmt" 
) 

func main() { 
    time, err := time.Parse("Jan 2006", "Feb 2020") 
    if err != nil { 
     panic(err) 
    } 
    fmt.Println(time) 
} 

布局格式,你可以找到here

相关问题