Convert time.Time to string

前端 未结 5 2218
时光说笑
时光说笑 2020-12-04 15:12

I\'m trying to add some values from my database to a []string in Go. Some of these are timestamps.

I get the error:

cannot use U.

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 15:35

    Go Playground http://play.golang.org/p/DN5Py5MxaB

    package main
    
    import (
        "fmt"
        "time"
    )
    
    func main() {
        t := time.Now()
        // The Time type implements the Stringer interface -- it
        // has a String() method which gets called automatically by
        // functions like Printf().
        fmt.Printf("%s\n", t)
    
        // See the Constants section for more formats
        // http://golang.org/pkg/time/#Time.Format
        formatedTime := t.Format(time.RFC1123)
        fmt.Println(formatedTime)
    }
    

提交回复
热议问题