如何在Go中将今天的日期格式化为dd-mm-yyyy?

huangapple go评论82阅读模式
英文:

How to format todays date in go as dd-mm-yyyy?

问题

我正在尝试在Go语言中格式化今天的日期,但似乎在一些我认为很简单的事情上遇到了困难。

我想以dd-mm-yyyy的格式获取今天的日期。

有什么想法吗?

谢谢

英文:

I am trying to format todays date in golang and seem to be struggling with something i deem to be quite simple.

I am trying to get todays date in the format of dd-mm-yyy

any ideas?

thanks

答案1

得分: 25

这是Go Playground中的工作方式:https://play.golang.org/p/kBjTxZS9Y7

以下是代码:

package main

import (
	"fmt"
	"time"
)

func main() {
	fmt.Println(time.Now().Format("02-01-2006"))
}

请注意,这是一个打印当前日期的简单程序。

英文:

It works this way in Go Playground: https://play.golang.org/p/kBjTxZS9Y7

Here is the code:

package main

import (
	"fmt"
	"time"
)

func main() {
    fmt.Println(time.Now().Format("02-01-2006"))
}

huangapple
  • 本文由 发表于 2017年4月18日 02:03:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/43456851.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定