Get current time as formatted string in Go?

后端 未结 8 521
北荒
北荒 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))
    }
    
    0 讨论(0)
  • 2021-01-30 01:58

    Find more info in this post: Get current date and time in various format in golang

    This is a taste of the different formats that you'll find in the previous post:

    0 讨论(0)
提交回复
热议问题