我正在尝试使用解析日期自动填充GSP模板上的文本字段:
<label>Date of birth(mm-dd-yyyy):</label> <g:textField name="dateOfBirth" style ="border-radius: 5px"
value="${Date.parse('dd-MM-yyyy', recordToEdit.dateOfBirth)}"></g:textField><br>
我得到了这个:
| 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"
答案 0 :(得分:1)
您的格式'dd-MM-yyyy'
与您要解析的字符串不对应
应该是
Date.parse( 'EEE MMM d HH:mm:ss Z yyyy', 'Thu Nov 23 00:00:00 UTC 1972' )
然后你可以格式化它:
Date.parse( 'EEE MMM d HH:mm:ss Z yyyy', 'Thu Nov 23 00:00:00 UTC 1972' ).format( 'dd-MM-yyy' )