govaluate icon indicating copy to clipboard operation
govaluate copied to clipboard

How to implement output the current time

Open amiaogo opened this issue 1 year ago • 1 comments

For example, the expression:time.Now().Format("2006-01-02 15:04:05"),Is it supported?

amiaogo avatar May 19 '23 09:05 amiaogo

    functions := map[string]govaluate.ExpressionFunction {
	"timeFormat": func(args ...interface{}) (interface{}, error) {
		return time.Now().Format("2006-01-02 15:04:05"), nil
	},
}
expString := "timeFormat()"
expression, _ := govaluate.NewEvaluableExpressionWithFunctions(expString, functions)

result, _ := expression.Evaluate(nil)

s6816112 avatar Jun 26 '23 02:06 s6816112