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
Release: 2024-02-06 11:42:15
forward
1176 people have browsed it

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
}
Copy after login

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!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template