Java.util.Date() - format output

0

Hi.

'd like to change format of actual date. My textfield:

"Day " + new java.util.Date() 

Output is:

Day Wed Jan 28 13:32:40

 

But required output is:

Day 28.01.2009

How to write it correctly?

Thanx for answerr.

 

foster's picture
13
Joined: Jul 1 2008 - 10:49pm
Last seen: 11 years 2 weeks ago

4 Answers:

0

On ireport u can set a defined patter for your field ;right click on the field and check the property .leave the class expression as java.lang.Date and edit the pattern.

Code:
http://www.google.it/firefox?client=firefox-a&rls=com.ubuntu:en-US:official</td></tr></tbody></table>
fgar's picture
33
Joined: Oct 15 2008 - 4:29am
Last seen: 10 years 9 months ago
0
But I have class expression as string because of joinig some string together in this textfield. And one is Date.
foster's picture
13
Joined: Jul 1 2008 - 10:49pm
Last seen: 11 years 2 weeks ago
5

foster,

 

In general it's better to use a localized date format. Something like this:
DateFormat.getDateInstance(DateFormat.SHORT, $P{REPORT_LOCALE}).format( new java.util.Date() )

 

But if you prefer to hardcode the format in your case, you can do it like this:
new SimpleDateFormat("dd.MM.yyyy").format( $P{MyDateParam} )

 

See more details here:
http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html

 

Regards,
Matt

mdahlman's picture
8940
Joined: Mar 13 2007 - 2:43am
Last seen: 4 years 8 months ago

Thanks a lot I was trying something like this and got the solution from your post

raj.john - 5 years 1 month ago
0
Thanx for answer. My mistake was: "Dňa " + new SimpleDateFormat("dd.MM.yyyy").format(java.util.Date()) But correct is: "Dňa " + new SimpleDateFormat("dd.MM.yyyy").format(new java.util.Date())
foster's picture
13
Joined: Jul 1 2008 - 10:49pm
Last seen: 11 years 2 weeks ago
Feedback