now := time.Now()
fmt.Println(now)
// Now函数返回的是一个结构体
fmt.Printf("年:%v \n",now.Year())
fmt.Printf("月:%v \n",now.Month())
fmt.Printf("月:%v \n",int(now.Month())) //转换为int类型的月份
fmt.Printf("日:%v \n",now.Day())
fmt.Printf("时:%v \n",now.Hour())
fmt.Printf("分:%v \n",now.Minute())
fmt.Printf("秒:%v \n",now.Second())
//日期的格式化
fmt.Println("-----------------------------------")
fmt.Printf("当前的年月日:%d-%d-%d 时分秒:%d:%d:%d \n",
now.Year(),now.Month(),now.Day(),now.Hour(),now.Minute(),now.Second())
dataStr := fmt.Sprintf("当前的年月日:%d-%d-%d 时分秒:%d:%d:%d \n",
now.Year(),now.Month(),now.Day(),now.Hour(),now.Minute(),now.Second())
fmt.Println(dataStr)
// 注意:这个参数的的时间点必须时固定的,不能修改,因为这个时间段点是Go语言的创建时间
dataStr2 := now.Format("2006/01/02 15:04:05")
fmt.Println(dataStr2)