• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 122
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 122
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So using format: format="MMM dd, yyyy"

Wouldnt this accomplish the MEDIUM format just like Date Format?
 
E Robb
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 122
Mac IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what exactly did format="MMM dd, yyyy" output for each?
 
E Robb
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic