10. About Time
Activity 10.01: Formatting a Date According to User Requirements
Solution:
- Create a file called
Chapter_10_Activity_1.go
and initialize it with the following code:package main import "fmt" import "time" import "strconv" func main(){
- Capture the following values:
date
,day
,month
,year
,hour
,minute
, andsecond
:Â Â date := time.Now() Â Â day := strconv.Itoa(date.Day()) Â Â month := strconv.Itoa(int(date.Month())) Â Â year := strconv.Itoa(date.Year()) Â Â hour := strconv.Itoa(date.Hour()) Â Â minute := strconv.Itoa(date.Minute()) Â Â second := strconv.Itoa(date.Second())
- Print the concatenated output:
  fmt.Println(hour + ":" + minute + ":" + second + " " + year + "/" + month + "/" + day) }
The expected output is as follows (note that this depends on when you run the code):
15:32:30 2019/10/17