Home >Backend Development >Golang >How to parse 'April 2023' into a time.Time object in golang

How to parse 'April 2023' into a time.Time object in golang

WBOY
WBOYforward
2024-02-06 11:42:151206browse

How to parse April 2023 into a time.Time object in golang

Question content

I cannot parse a date string like April 2023 into a time.Time object for comparison in golang datetime object.


Correct answer


package main

import (
    "fmt"
    "time"
)

func main() {
    t, err := time.Parse("January 2006", "April 2023")
    if err != nil {
        panic(err)
    }
    fmt.Println(t)
    // 2023-04-01 00:00:00 +0000 UTC
}

The above is the detailed content of How to parse 'April 2023' into a time.Time object in golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Golang: unused functionsNext article:Golang: unused functions