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