代码之家  ›  专栏  ›  技术社区  ›  sinusGob

我怎么把时间打印成这个格式23:44:22.184320

go
  •  -3
  • sinusGob  · 技术社区  · 6 年前

    如何按此格式打印时间?

    23:44:22.184320
    

    我试过的是

    func main() {
       // Which will print to the current time
       fmt.Println(time.Now())
    
       // How do I convert to
       // 23:44:22.184320
    }
    

    我已经检查了这个链接,但我不知道怎么做 https://gobyexample.com/time-formatting-parsing

    谢谢!

    1 回复  |  直到 6 年前
        1
  •  2
  •   ssemilla    6 年前

    改为使用:

    time.Now().Format("15:04:05.999999")
    

    请注意 time 包装是:

    Mon Jan 2 15:04:05 MST 2006
    

    time package

    推荐文章