> For the complete documentation index, see [llms.txt](https://sec88.0x88.online/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sec88.0x88.online/programming/go/package/time.md).

# Time

**Overview:**

* The `time` package in Go provides functionality for working with time-related operations, such as getting the current time, sleeping, timers, and tickers.
* It offers structs like `Time`, `Duration`, and functions like `Now()`, `Sleep()`, `After()`, `Ticker()`, and `NewTimer()` for various time-related tasks.

**Usage of `time.After()`, `time.Ticker`, and `time.NewTimer()`:**

1. **`time.After()`**:

   * `time.After(duration)` returns a channel that receives the current time after the specified duration.
   * It's commonly used to create a timeout mechanism or to schedule an action to occur after a specific duration.
   * It's a non-blocking operation.

   Example:

   ```go
   select {
   case <-time.After(1 * time.Second):
       fmt.Println("Timeout!")
   }
   ```
2. **`time.Ticker`**:

   Example:

   ```go
   ticker := time.NewTicker(1 * time.Second)
   defer ticker.Stop()

   for {
       select {
       case <-ticker.C:
           fmt.Println("Tick")
       }
   }
   ```
3. **`time.NewTimer()`**:

   Example:

   ```go
   timer := time.NewTimer(2 * time.Second)
   defer timer.Stop()

   select {
   case <-timer.C:
       fmt.Println("Timer expired")
   }
   ```

**Using with `select`:**

Example:

```go
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

timer := time.NewTimer(5 * time.Second)
defer timer.Stop()

for {
    select {
    case <-ticker.C:
        fmt.Println("Tick")
    case <-timer.C:
        fmt.Println("Timer expired")
        return
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sec88.0x88.online/programming/go/package/time.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
