Convert time.Time to string

前端 未结 5 2220
时光说笑
时光说笑 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 15:38

    Please find the simple solution to convete Date & Time Format in Go Lang. Please find the example below.

    Package Link: https://github.com/vigneshuvi/GoDateFormat.

    Please find the plackholders:https://medium.com/@Martynas/formatting-date-and-time-in-golang-5816112bf098

    package main
    
    
    // Import Package
    import (
        "fmt"
        "time"
        "github.com/vigneshuvi/GoDateFormat"
    )
    
    func main() {
        fmt.Println("Go Date Format(Today - 'yyyy-MM-dd HH:mm:ss Z'): ", GetToday(GoDateFormat.ConvertFormat("yyyy-MM-dd HH:mm:ss Z")))
        fmt.Println("Go Date Format(Today - 'yyyy-MMM-dd'): ", GetToday(GoDateFormat.ConvertFormat("yyyy-MMM-dd")))
        fmt.Println("Go Time Format(NOW - 'HH:MM:SS'): ", GetToday(GoDateFormat.ConvertFormat("HH:MM:SS")))
        fmt.Println("Go Time Format(NOW - 'HH:MM:SS tt'): ", GetToday(GoDateFormat.ConvertFormat("HH:MM:SS tt")))
    }
    
    func GetToday(format string) (todayString string){
        today := time.Now()
        todayString = today.Format(format);
        return
    }
    

提交回复
热议问题