Here is my program
package main
import "fmt"
import "time"
import "strconv"
import "strings"
func main() {
t := time.Date(2016, 10, 30, 14, 0, 0, 0, time.UTC)
year, month, day := t.Date()
hr := t.Hour()
s := []string{strconv.Itoa(year), strconv.Itoa(int(month)), strconv.Itoa(day)}
date := strings.Join(s, "")
s = []string{date, strconv.Itoa(hr)}
date = strings.Join(s, "_")
fmt.Println(date)
}
The output is
20161030_14
If I replace
t := time.Date(2016, 10, 30, 14, 0, 0, 0, time.UTC)
with
t := time.Date(2016, 6, 3, 9, 0, 0, 0, time.UTC)
then the output is
201663_9
but I hope it outputs
20160603_09
i.e. the month, day and hour should all be two-character long with possibly adding 0
in front. How can I do that?
Or if you were me, what would be your program which implements the same thing?
Thanks.