jasper reports - How to format java.time.LocalDateTime and java.time.LocalDate with pattern? -
in following snipped property $f
of class java.time.localdatetime
or java.time.localdate
.
<textfield pattern="ee. dd.mm.yyyy"> <reportelement...> </reportelement> <textfieldexpression><![cdata[$f{thelocaldatetime}]]></textfieldexpression> </textfield>
how can format property textfield pattern
in jasper reports?
to use pattern attribute in current version of jasper-report date/time object need java.util.date
class or 1 of it's subclasses.
the solution convert java.time.localdate
, java.time.localdatetime
converting java.util.date
<textfield pattern="ee. dd.mm.yyyy"> <reportelement...> </reportelement> <textfieldexpression><![cdata[java.util.date.from($f{thelocaldate}.atstartofday(java.time.zoneid.systemdefault()).toinstant())]]></textfieldexpression> </textfield>
<textfield pattern="ee. dd.mm.yyyy"> <reportelement...> </reportelement> <textfieldexpression><![cdata[java.util.date.from($f{thelocaldatetime}.atzone(java.time.zoneid.systemdefault()).toinstant())]]></textfieldexpression> </textfield>
converting java.sql.timestamp
from java.time.localdate
<textfield pattern="ee. dd.mm.yyyy"> <reportelement...> </reportelement> <textfieldexpression><![cdata[java.sql.timestamp.valueof($f{thelocaldate}.atstartofday())]]></textfieldexpression> </textfield>
from java.time.localdatetime
<textfield pattern="ee. dd.mm.yyyy"> <reportelement...> </reportelement> <textfieldexpression><![cdata[java.sql.timestamp.valueof($f{thelocaldatetime})]]></textfieldexpression> </textfield>
note: applying pattern preferable solution, specially when exporting excel since correct class passed poi (hence excel recognize column date , apply same formatting in pattern)
Comments
Post a Comment