• Post Reply Bookmark Topic Watch Topic
  • New Topic

fmt date format question  RSS feed

 
aditee sharma
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can somebody tell me how to display the "AM/PM" part in a date format ?
I need to format date like this:
06/25/08 08:36:11 PM
I managed the part till "06/25/08 08:36:11" but have no clue about AM/PM.
thank you,
Aditee
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The javadocs for the java.text.SimpleDateFormat class have that information.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There would be two ways to do this. The first one uses the DateFormat pre-formatted styles.
<fmt:formatDate value="${now}" type="both" dateStyle="short" timeStyle="medium"/>

The result for today would be 8/7/08 3:18:13 PM which isn't exactly the format you wanted, but is close.

Or you can use the SimpleDateFormat parrern:
<fmt:formatDate value="${now}" pattern="MM/dd/yy hh:mm:ss a"/>

The result being 08/07/08 03:18:13 PM which is pretty mush exactly what you want, I think.

The difference would be localization. In a locale where dates are shown as: yy.MM.dd rather than MM/dd/yy then the first option would be more recognizable to the user, while the second option may take some time for interpretation.
 
aditee sharma
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help.
However, even after putting the 'a' in the format I get :
Thu Aug 07 11:04:18 EDT 2008
whereas I needed just :
Thu Aug 07 11:04:18 AM

Do I have to set the time zone/locale for this ?
thank you,
Aditee
 
aditee sharma
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for the confusion.
Its comming out in some other format than expected...
I did this :
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the problem is solved? (A quick test shows that the pattern you posted produces exactly the output you wanted.)
 
aditee sharma
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, Ulf,
the actual problem was somewhere between my table and my chair :-)
(forgot to close the enclosing display tag ).
Thanks a lot.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aditee sharma:
sorry for the confusion.
Its comming out in some other format than expected...
I did this :


Did this format fix your problem? On my machine I copy and pasted your code, changed the value to a known java.util.Date and got:
08/07/2008 14:06:25 PM


edit: I'm a slow poke. :-)
[ August 07, 2008: Message edited by: Steve Luke ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!