从天开始从时间接收字符串的简单方法.Now()

I'm trying to get the day as a string from a time.Now() instance.

now := time.Now() // .String() would give me the entire date as a string which I don't need
day := now.Day()) // is what I want but as a String.

So string(day) tells me "can not convert day to string".

For me now.Day().String() would be nice but there is no such method...

I could now try to take time.Now().String() and manipulate until the day is left over. But there should be a easier way to do it...

Use strconv to convert int to string

strconv.Itoa(day)

You can import and use strconv as KibGzr mentioned. Just to give a complete example:

package main

import (
    "fmt"
    "time"
    "strconv"
)

func main() {
    now := time.Now() 
    day := now.Day()
    fmt.Printf("%T
",(day))
    fmt.Println(strconv.Itoa(day))
    dayString := strconv.Itoa(day)
    fmt.Printf("%T",(dayString))
}

https://play.golang.org/p/Mqs24FJhCoi