HijrahChronology.INSTANCE.date(LocalDate.of(year, month, day));
此代码用于使用UmalQuraCalendar
API将日期转换为Hijri日期。
<g:formatDate date="${hijrahDate}" />
引发了一个例外:
Class
java.lang.IllegalArgumentException
Message
Unknown class: org.codehaus.groovy.grails.web.util.StreamCharBuffer
如何格式化GSP中的java.time.chrono.HijrahDate
对象?
答案 0 :(得分:0)
<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
属性。
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));
}
}
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)
}
}
}