Get current time as formatted string in Go?

后端 未结 8 530
北荒
北荒 2021-01-30 01:15

What\'s the best way to get the current timestamp in Go and convert to string? I need both date and time in eg. YYYYMMDDhhmmss format.

8条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 01:57

    For readability, best to use the RFC constants in the time package (me thinks)

    import "fmt" 
    import "time"
    
    func main() {
        fmt.Println(time.Now().Format(time.RFC850))
    }
    

提交回复
热议问题