This section contains the Golang Date & Time find output programs (set 2) with their output and explanations.
Program 1:
package main
import "fmt"
import "time"
func main() {
date := time.Date(0, 0, 0, 10, 10, 10, 0, time.UTC)
res := date.AddTime(10, 5, 7)
fmt.Println("Res : ", res)
}
Program 2:
package main
import "fmt"
import "time"
func main() {
date1 := time.Date(2022, 2, 5, 0, 0, 0, 0, time.UTC)
date2 := time.Date(2021, 1, 14, 0, 0, 0, 0, time.UTC)
fmt.Println("Result: ", date1.After(date2))
}
Program 3:
package main
import "fmt"
import "time"
func main() {
time1 := time.Date(2020, 2, 5, 10, 5, 20, 0, time.UTC)
time2 := time.Date(2020, 2, 5, 13, 10, 30, 0, time.UTC)
diff := time2.Subtract(time1)
fmt.Printf("Difference of t1 and t2 is: %v", diff)
}
Answer Program 1:
Output:
Explanation:
The above program will generate a syntax error because AddTime() is not defined in the Time class.
Answer Program 2:
Output:
Explanation:
In the above program, we created two date objects date1 and date2. Here, we used After() method, which is used to compare two dates and return a Boolean value.
Answer Program 3:
Output:
Explanation:
The above program will generate a syntax error because Subtract() is not a built-in method. The Sub() method is used to subtract a date from another date.
The correct program is given below:
need an explanation for this answer? contact us directly to get an explanation for this answer