diff --git a/pkg/expr/func_time.go b/pkg/expr/func_time.go index 84b9877a6..0b63e94c7 100644 --- a/pkg/expr/func_time.go +++ b/pkg/expr/func_time.go @@ -190,10 +190,15 @@ func prepMod(base interface{}, mod interface{}) (*time.Time, int, error) { // https://github.com/lestrrat-go/strftime#supported-conversion-specifications func strfTime(base interface{}, f string) (string, error) { t, _, err := prepMod(base, 0) + if err != nil { return "", err } - o, _ := strftime.Format(f, *t, strftime.WithMilliseconds('b')) + + o, _ := strftime.Format(f, *t, + strftime.WithMilliseconds('b'), + strftime.WithUnixSeconds('L')) + return o, nil } diff --git a/pkg/expr/func_time_test.go b/pkg/expr/func_time_test.go index 9ccbfbd12..d333a47e1 100644 --- a/pkg/expr/func_time_test.go +++ b/pkg/expr/func_time_test.go @@ -134,3 +134,10 @@ func Example_subErrorCheck() { // output: // error: can not evaluate sub(ghd, hgp): expecting 2nd input to be less than 1st input } + +func Example_unix() { + eval(`strftime(ghd, "%L")`, exampleTimeParams) + + // output: + // 728650800 +}