Get current date in a livetemplate groovy script.
So I don't know groovy, but I tried this after trying it in an online groovy compiler :
groovyScript("println new Date().format('yyyy-MM-dd')") I've tried with and without println.
That gives me this error message :
(No signature of method: java.util.Date.format() is applicable for argument types: (String) values: [yyyy-MM-dd]
Possible solutions: from(java.time.Instant), stream(), getAt(java.lang.String), parse(java.lang.String), print(java.io.PrintWriter), print(java.lang.Object))
I have also tried this one, but after checking it gives the same error in the online groovy compiler
groovyScript("def v = new Date(); f = SimpleDateFormat('yyyy-MM-dd'); f.format(v)") Which results in
(No signature of method: Script1.SimpleDateFormat() is applicable for argument types: (String) values: [yyyy-MM-dd])
I've then tried this one that works !
groovyScript("import java.time.LocalDate; l = LocalDate.now(); l")To avoid frustration with writing groovy in the future, can someone help me understand
- why the first example works in https://onecompiler.com/groovy/
- what's wrong with the 2nd example ?
Please sign in to leave a comment.