-3

I'm using code similar to this:

import (
    "fmt"
    "time"
)

func main() {
    now := time.Now()
    fmt.Println(now.Round(0))
    y, m, d := now.Date()
    fmt.Println(y, int(m), d)

}

Using this code how can I combine y, m and d so that it would be of format "yyyy-mm-dd" or like "2023-04-18"?

Angie
  • 183
  • 3
  • 13

1 Answers1

0

Use Format:

func main(){
   now := time.Now()
   fmt.PrintLn(now.Format("2006-02-01"))
}

Format uses as reference the date of January, 2nd 2006, so for example: ("02-01-2006") means "DD-MM-YYY"