没有方法签名:java.util.Date.parse()适用于参数类型

时间:2019-02-09 14:27:25

标签: java groovy

我在安装了最新Groovy的Eclipse中收到此错误消息。

Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: java.util.Date.parse() is applicable for argument types: (String, String) values: [d/M/yyyy H:m:s, 28/09/2010 16:02:43]
Possible solutions: parse(java.lang.String), wait(), clone(), grep(), any(), use([Ljava.lang.Object;)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70)
    at org.codehaus.groovy.vmplugin.v7.IndyGuardsFiltersAndSignatures.unwrap(IndyGuardsFiltersAndSignatures.java:175)
    at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:234)
    at GroovyLearn.main(GroovyLearn.groovy:222)

String theDate = "28/09/2010 16:02:43";
def newdate = new Date().parse("d/M/yyyy H:m:s", theDate);

预期结果:Tue Sep 28 16:02:43 CEST 2010

实际结果:出现无法正确解析的错误

1 个答案:

答案 0 :(得分:4)

parseDate上的静态方法

代替

def newdate = new Date().parse("d/M/yyyy H:m:s", theDate)

您需要做

def newdate = Date.parse("d/M/yyyy H:m:s", theDate)