解决!
用例 :
<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
隐式使用
- if
type="hijri"
,format
仅包含dd
, MMM
or/and 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));
}
}
标签库:
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)
}
}
}