How to format date to dd.MM.yyyy hh:mm

1

I get "time" from datebase, and I want the jasper report show the time in "dd.MM.yyyy hh:mm" format, what should I do in 
 

Code:
<textFieldExpression class="java.lang.String"><![CDATA[$F{time}]]></textFieldExpression>

(what to do if "time" is String type, and what to do if "time" is Date type )
??



Post Edited by Xi Chen at 04/08/09 16:29
mellon's picture
22
Joined: Apr 8 2009 - 9:16am
Last seen: 10 years 1 month ago

4 Answers:

2
Remember everything in iReport are objects you should just use a SimpleDateFormat, take a look at the class description in API. First convert your String to a Date object new SimpleDateFormat("dd.MM.yyyy.HH.mm").format(new Date())
caifanmayor's picture
Joined: Jun 29 2007 - 9:39am
Last seen: 11 years 10 months ago
1

caifanmayor
Wrote:

Remember everything in iReport are objects you should just use a SimpleDateFormat, take a look at the class description in API. First convert your String to a Date object new SimpleDateFormat("dd.MM.yyyy.HH.mm").format(new Date())

Hi, I want to do the date formate inside *.jrxml file code, how to do it? Could you please give some sample code based on my code bellow? (I am quite new in Jasperreport, I do not know how to do the date format inside *.jrxml) thanks.

Code:
<textFieldExpression class="java.lang.String"><![CDATA[$F{time}]]></textFieldExpression></td></tr></tbody></table>
mellon's picture
22
Joined: Apr 8 2009 - 9:16am
Last seen: 10 years 1 month ago
2

if "time" is of  type String:

<textFieldExpression class="java.lang.String"><![CDATA[new java.text.SimpleDateFormat("dd.MM.yyyy hh:mm").format(new java.text.SimpleDateFormat("dd.MM.yyyy hh:mm").parse($P{time}))]]></textFieldExpression>

if "time" is of type Date:

<textFieldExpression class="java.lang.String"><![CDATA[new java.text.SimpleDateFormat("dd.MM.yyyy hh:mm").format($P{time})]]></textFieldExpression>

dman's picture
76
Joined: Apr 6 2009 - 2:20am
Last seen: 4 years 7 months ago
0

Why don't work?

elenauscom.u's picture
Joined: May 29 2018 - 4:40am
Last seen: 9 months 2 weeks ago
Feedback