dcsimg
Adding new character to date format.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Akshay_B
Posted On:   Thursday, July 3, 2008 03:04 AM

I want to give users a facility to view the quarters in which the date belongs to, embedded in itself. So, if the user specifies the format as "MMM/dd/yyyy/Q", then I want the output to be, "Jul/02/2008/4". I want to know, how do we allow the SimpleDateFormat to accept this new character "Q" and be able to apply it as the pattern. I tried adding "Q" to the SimpleDateFormat.setDateFormatSymbols (DateFormatSymbols) by adding a "Q" in the DateFormatSymbols object I am passing, but it doesnt help, i am still getting error if I try to apply the pattern including the "Q" in it. Any help would be appreciated :)    More>>

I want to give users a facility to view the quarters in which the date belongs to, embedded in itself.



So, if the user specifies the format as "MMM/dd/yyyy/Q", then I want the output to be, "Jul/02/2008/4".



I want to know, how do we allow the SimpleDateFormat to accept this new character "Q" and be able to apply it as the pattern. I tried adding "Q" to the SimpleDateFormat.setDateFormatSymbols (DateFormatSymbols) by adding a "Q" in the DateFormatSymbols object I am passing, but it doesnt help, i am still getting error if I try to apply the pattern including the "Q" in it.



Any help would be appreciated :)

   <<Less

Re: Adding new character to date format.

Posted By:   Stephen_McConnell  
Posted On:   Thursday, July 3, 2008 10:18 AM

Have you read the JavaDocs on the SimpleDateFormat??? There is no formatting information for adding "Q" and nothing that will interpret it. The documentation is there. You can't make up a piece of formatting information and figure it will work.


What you will have to do is Extend the SimpleDateFormat... so you can add the "Q" to the end of the method. You could over-ride the "setDateFormatSymbols" method to look for the Q and if the Q exists, you would set a flag and add it to your output format by over-riding the "format" method.


Stephen McConnell

About | Sitemap | Contact