Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany
Accepted Solution

SimpleDateFormat giving different results for the same formatting string

I use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/i18n/SimpleDateFormat.html to format my time and date fields.

I got a bug report that a device on English(UK) has a glitch where the time goes off the screen, and i was able to reproduce that on both device and simulator.

 

This is the pattern string i use: hh:mma

(2 digits hour, colon, 2 digits minute, and a single letter for 'a' or 'p')

 

On English or English(US) i get the desired result, for example '12:12p'

On English(UK) i get two letters for the a/p marker, for example '12:12pm'

(as if i had used 'hh:mmaa' ).

 

Is this the desired behavior? My customer does not like it and wants a single look and feel, with only one letter for 'a' or 'p', and i am somewhat hesitatant to use aubstring... 

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: SimpleDateFormat giving different results for the same formatting string

Hi Simon,

 

According to the docs, the SimpleDateFormat works in a 'locale-sensitive manner' so it looks like it works correctly.

 

If you don't want to use substring, you might want to consider extending DateFormat or SimpleDateFormat and returning the desired format regardless of the locale.

 

Hope that helps,

 

E.

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: SimpleDateFormat giving different results for the same formatting string

It says:
Most patterns require or are affected by a length.
And the table says about 'a':
a a p
aa PM
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: SimpleDateFormat giving different results for the same formatting string

To be honest, I am surprised that you get a instead of am, even in the US.  In my opinion, here in the UK anyway, people would be confused with just an a or a p, they expect am and pm. 

 

I get round this issue by giving people the 24 hour time.....

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: SimpleDateFormat giving different results for the same formatting string

I usually do that as well, but our customer specifically requested a localized formatting for time and date.
I have the pattern in my resource files as the requested values are not manageable with the standard dateformat.

well, i've submitted feedback on the API doc entry, either the doc is wrong or the OS has a bug.
I am using substring if the string endsWith(am or pm) now...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter