GeeCON Prague 2014*
The moose likes Struts and the fly likes <s:date name= formatDate & i18nInteceptor" title="" /> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "<s:date name="%{new java.util.Date()}" />  formatDate & i18nInteceptor" Watch "<s:date name="%{new java.util.Date()}" />  formatDate & i18nInteceptor" New topic
Author

<s:date name="%{new java.util.Date()}" /> formatDate & i18nInteceptor

E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
In my tiles to display the date on the header of each page I am using <s:date name="%{new java.util.Date()}" /> It appears to work great & the i18nInteceptor returns dates English Dec 29, 2010 7:33:51 PM & French 29 déc. 2010 19:38:47

My question is using <s:date name="%{new java.util.Date()}" /> is there any way to tell it I only want the month, day & date and not the time. I dont want to specify the date format I want the localization to do that I just what to specifiy what is returned in the date object.

Thanks,
Earl
Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

Earl,

Have you tried the format attribute for the s:date tag?



Where you can specify whatever format you want.

-Lucas
E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
Hey Lucas,
I have tried using format="yyyy-MM-dd" but it overrides the i18nInteceptor. As an example

If I use:


Then change my Struts 2.1 inteceptor using:



I get the following results:
English: Dec 29, 2010 8:09:07 PM
French: 29 déc. 2010 20:46:31

So if I set my date tag to:


I get the following results:
English: 2010-12-29
French: 2010-12-29

As you can see by setting the format property its over writing the i18n with the java.util.date. I want the java.util.date format determined by the i18nInteceptor but I want to specify which parts of the date are returned.

Im really pleased with struts returning the date in the proper language & format I just want to specify which parts of the dates are returned. IE I would like to exclude the time portion of the stamp returned.

Something like SHORT or MEDIUM for the java.util.date object.

Cheers,
Earl
Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

So using format: format="MMM dd, yyyy"

Wouldnt this accomplish the MEDIUM format just like Date Format?
E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
I would like the date format displayed as:

English: Dec 29, 2010
French: 29 déc. 2010

Using with struts 2.1 i18nInteceptor

There is some internationalization as the dates are displayed as:

English: Dec 29, 2010 8:09:07 PM
French: 29 déc. 2010 20:46:31



Hard coding the date format using the format attribute of s:date displays the date as this:
English: 2010-12-29 (incorrect format for english should be 12/29/2010)
French: 2010-12-29 (incorrect date format for french should be 29/12/2010)

There is no internationalization in using format="yyyy-MM-dd" with s:date. This is basically hard coding a format and no matter what country you are from you will always see the date format in the hard coded version and not the locale you have chosen.

If Im missing something here please let me know.



Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

So what exactly did format="MMM dd, yyyy" output for each?
E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
You have cracked the case wide open! Thats the solution!!! I was using yyyy-MM-dd

This is the Answer, Brilliant well done Lucas:



English: Dec 29, 2010
French: déc. 29, 2010

I spent a whole day messing around with this you solved it in 15 mins. Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <s:date name="%{new java.util.Date()}" /> formatDate & i18nInteceptor