HijrahChronology.INSTANCE.date(LocalDate.of(year, month, day));
该代码用于使用 JAVA8 的
UmalQuraCalendar
API将日期转换为Hijrah Date。<g:formatDate date="${hijrahDate}" />
引发异常:Class
java.lang.IllegalArgumentException
Message
Unknown class: org.codehaus.groovy.grails.web.util.StreamCharBuffer
如何在GSP中格式化
java.time.chrono.HijrahDate
对象? 最佳答案
解决!
用例 :
<abdennour:formatDate showTime="true" date="${new Date()}" type="hijri"/>
另一个
<abdennour:formatDate showTime="true" date="${new Date()}" format="dd/MMM/YYYY" type="hijri"/>
笔记:
type
属性不存在,这意味着您隐式使用g:formatDate
type="hijri"
,format
仅包含dd
,MMM
或/和YYYY
,则要显示时间,请添加showTime
属性。API
服务内容:
class UtilsService {
java.time.chrono.HijrahDate toHijri(Date date){
//return HijrahChronology.INSTANCE.date(Instant.ofEpochMilli(date.getTime()));
Calendar cl=Calendar.getInstance()
cl.setTime(date);
return toHijri(cl.get(Calendar.YEAR), cl.get(Calendar.MONTH)+1, cl.get(Calendar.DATE));
}
java.time.chrono.HijrahDate toHijri(int year,int month,int day){
return HijrahChronology.INSTANCE.date(LocalDate.of(year, month, day));
}
}
Taglib:
class UtilsTagLib {
static namespace='abdennour'
def utilsService
def formatDate={at,b->
if(at?.type && at?.type?.toLowerCase()?.startsWith("hij")){
at.dateh=utilsService.toHijri(at.date);
if(!at?.format){at?.format='dd-MM-YYYY'}
//at?.fullformat=at?.format
//at?.format='dd-MMM-YYYY'
String format=at.dateh?.format(DateTimeFormatter.ofPattern(at?.format))
if(at?.showTime){
Calendar cl=Calendar.getInstance();cl.setTime(at?.date);
format=format+' '+cl.get(Calendar.HOUR)+':'+cl.get(Calendar.MINUTE)
}
out << format
}else{
out << g.formatDate(at)
}
}
}
关于grails - g:formatDate grails taglib不适用于java.time.chrono.HijrahDate实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27121299/