I get lots of data and serialize them to a struct with a field 'Create_time' of type Int64, such as:
type Log struct {
ID int `mapstructure:"id"`
Create_time int64 `mapstructure:"create_time,omitempty"`
}
Now if I want to filter data between 2021-10-24 00:00:00 and 2021-10-25 00:00:00, how can I do ?
CodePudding user response:
Assuming Create_time
is obtained using Time.Unix()
, you can find the Unix
representation for the range, and then filter:
from:=time.Date(2021,10,24,0,0,0,0,time.Local).Unix()
to:=time.Date(2021,10,25,0,0,0,0,time.Local).Unix()
Then find all elements with Create_time>=from && Create_time<=to
.
Make the necessary changes about the timezones. If the Create_time
is milli/micro/nanoseconds, then use UnixMilli
, UnixMicro
, or UnixNano
.