Go function to check if it's Daylight Saving Time (DST)
In Ruby, there's the Time#dst? function, which returns true if the current time is in Daylight Saving Time (DST). Is there a similar function available in the Go standard library?
The answer is yes. In August 2021, Go 1.17 was released, which introduces the time.Time method IsDST.
Usage:
The syntax of IsDST is as follows:
<code class="go">func (t Time) IsDST() bool</code>
Example:
Here's an example of how to use the IsDST method:
<code class="go">package main import ( "fmt" "time" ) func main() { t := time.Now() if t.IsDST() { fmt.Println("It is daylight saving time") } else { fmt.Println("It is not daylight saving time") } }</code>
The above is the detailed content of Is there a Go function to check if it\'s Daylight Saving Time (DST)?. For more information, please follow other related articles on the PHP Chinese website!