Java.util.Date() - format output

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
229
Joined: Jul 1 2008 - 10:49pm
Last seen: 15 years 2 months ago

4 Answers:

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
257
Joined: Oct 15 2008 - 4:29am
Last seen: 14 years 11 months ago
But I have class expression as string because of joinig some string together in this textfield. And one is Date.
foster's picture
229
Joined: Jul 1 2008 - 10:49pm
Last seen: 15 years 2 months ago

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
37526
Joined: Mar 13 2007 - 2:43am
Last seen: 8 years 10 months ago

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

raj.john - 9 years 4 months ago
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
229
Joined: Jul 1 2008 - 10:49pm
Last seen: 15 years 2 months ago
Feedback
randomness