Eli
(-)
April 18, 2022, 10:44pm
1
Hello mates, I am trying to set greetings according the to the current time, but I am facing the problem of 3 PM and 3 AM. How can I declare it since the hour is a integer?
Code:
hour, _, _ := time.Now().Clock()
if hour >= 18 && hour < 3 {
greetings(Dawn)
}
It could be something like:
if (hour < 12 && hour <= 3) || (hour > 12 && hour <= 18) {
greetings("Dawn")
}
The first condition check am times and the second one checks pm times
Eli
(-)
April 19, 2022, 12:04am
3
Thank you for the answer. How can I applied this thought to
if hour >= 18 && hour < 6 {
fmt.Println("\nGood evening.")
}
The statement never occurs because 18 is bigger than 6. I would like signalize that I am referring to 6AM of the another day.
Eli
(-)
April 19, 2022, 12:16am
4
Maybe it is too exhaustive, if so, do not worry about!
I can call evening until 24 and dawn from 0 to 6. My first desire was to call evening from 18 until 3 (next day) and from 3 to 6 call it dawn.
Below is also good.
Code:
if hour >= 18 && hour < 24 {
fmt.Println("\nGood evening.")
} else if hour >= 0 && hour < 6 {
fmt.Println("\nGood dawn.")
}