Skip to content
Related Articles

Related Articles

time.Time.After() Function in Golang With Examples

Improve Article
Save Article
  • Last Updated : 19 Apr, 2020
Improve Article
Save Article

In Go language, time packages supplies functionality for determining as well as viewing time. The Time.After() function in Go language is used to check if the stated time instant t is after the stated u or not. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions.

Syntax:

func (t Time) After(u Time) bool

Here, “t” is the stated time and “u” is the time that is present as an argument in the After() method.

Return Value: It returns true if “t” is present after “u” else it returns false.

Example 1:




// Golang program to illustrate the usage of
// Time.After() function
  
// Including main package
package main
  
// Importing fmt and time
import "fmt"
import "time"
  
// Calling main
func main() {
  
    // Declaring t and u in UTC
    t := time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC)
    u := time.Date(2019, 0, 0, 0, 0, 0, 0, time.UTC)
  
    // Calling After method
    res := t.After(u)
  
    // Prints output
    fmt.Printf("%v", res)
}

Output:

true

Example 2:




// Golang program to illustrate the usage of
// Time.After() function
  
// Including main package
package main
  
// Importing fmt and time
import "fmt"
import "time"
  
// Calling main
func main() {
  
    // Declaring t and u in UTC
    t := time.Date(2030, 0, 0, 0, 0, 0, 0, time.UTC)
    u := time.Date(2040, 0, 0, 0, 0, 0, 0, time.UTC)
  
    // Calling After method
    res := t.After(u)
  
    // Prints output
    fmt.Printf("%v", res)
}

Output:

false

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!