将UTC TZ时间转换为YYYY-MM-DD HH:MM:SS.zzzzzzz(Golang)

pftdvrlh  于 2022-12-07  发布在  Go
关注(0)|答案(1)|浏览(113)

我想以日期字符串为例,例如"2022-11-08T15:27:41.01333333Z",并将其转换为Golang中的"2022-11-08 15:27:41.01333333"。我实际上只是想将UTC日期转换为SQL Server可读的datetime2表达式。

package main

import (
    "fmt"
    "time"
)

func main () {
    t := "2022-11-08T15:27:41.01333333Z"
    // How to Parse?
}
dgsult0t

dgsult0t1#

这应该可行:

package main

import (
    "fmt"
    "time"
)

func main() {
    t := "2022-11-08T15:27:41.01333333Z"
    const layout = "2006-01-02T15:04:05.00000000Z07:00"
    x, err := time.Parse(layout, t)
    const render = "2006-01-02 15:04:05.00000000"
    fmt.Println(x.Format(render), err)
}

相关问题