1
1時間以内に発生したイベントについて、私のdbに照会する必要があります。 したがって、ととの間でイベントを取得したい場合は、(現在は24時間、または今は1日)です。1日前に現在の時刻を取得するにはどうすればよいですか?
私はこのアプローチを試みたが、それは間違っている -
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
// print the time now
fmt.Println(now)
then := time.Now()
diff := 24
diff = diff.Hours()
then = then.Add(-diff)
// print the time before 24 hours
fmt.Println(then)
// print the delta between 'now' and 'then'
fmt.Println(now.Sub(then))
}
にはどうすればその後、 == 1一日/ 24時間今前にすることができますか?
ありがとうございました! time.Hour
diff := 24 * time.Hour
then := time.Now().Add(-diff)
のような時間のパッケージで提供さDuration constants
をしたい場合どうもありがとう!超便利! – dodiku