Anonymous Human
Anonymous Human

Reputation: 1948

GSP date parsing error while trying to auto-populate a date into textfield

I am trying to auto populate a textfield on a GSP template with a parsed date as:

<label>Date of birth(mm-dd-yyyy):</label>&nbsp<g:textField name="dateOfBirth" style ="border-radius: 5px" 
                    value="${Date.parse('dd-MM-yyyy', recordToEdit.dateOfBirth)}"></g:textField><br>

and I get this:

| Error 2014-08-13 14:26:18,960 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver  - ParseException occurred when processing request: [POST] /FatcaOne_0/customer/displayRecordDetails - parameters:
secondaryId: 1
uniqueId: 903123A
Unparseable date: "Thu Nov 23 00:00:00 UTC 1972". Stacktrace follows:
Message: Unparseable date: "Thu Nov 23 00:00:00 UTC 1972"

Upvotes: 0

Views: 470

Answers (1)

injecteer
injecteer

Reputation: 20699

your format 'dd-MM-yyyy' does not correspond to the string you want to parse should be

Date.parse( 'EEE MMM d HH:mm:ss Z yyyy', 'Thu Nov 23 00:00:00 UTC 1972' )

then you can format it:

Date.parse( 'EEE MMM d HH:mm:ss Z yyyy', 'Thu Nov 23 00:00:00 UTC 1972' ).format( 'dd-MM-yyy' )

Upvotes: 1

Related Questions