简体   繁体   中英

How can cast object 'parseDate' with class 'java.lang.String' to class 'java.util.Date' in grails?

I'm new in grails and I'm trying to parse a String in a java.util.Date with grails. I've read here some questions with the method Date.parse but is deprecated and I want to do it with the new as Date. But, I'm not be able to do it.

Thanks in advance:

def date = '2016-05-26'
def minute = '00:00'

def dataSearch = date + minute as Date

There are a couple of different Date.parse methods, one of which is defined by the JDK and is deprecated, the other is defined by the Groovy JDK and is not deprecated. The deprecated JDK method, takes one argument whereas the Groovy JDK method takes two.

So the short answer is this:

Date d = Date.parse('yyyy-MM-dd', '2010-04-03')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM