Simpson
Simpson

Reputation: 593

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

Upvotes: 0

Views: 1498

Answers (1)

Dónal
Dónal

Reputation: 187399

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')

Upvotes: 1

Related Questions