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

Posts: 18
Registered: ‎06-02-2011
My Device: touch
My Carrier: java

Need to changte time format as per selected on device by user.

Hi All ,

I am facing one problem whiile showing the time format in 12 vs 24 hour clock.


Currently we are showing it is as 24 hour clock . But when user change time format on device to 12 hour format it should show reflect in app which is currently not happening.


My current implimentation is like thi


public static String toLongTimeString(long millis,
            StringBuffer reusableBuffer) {

        Calendar c = Calendar.getInstance();
        c.setTime(new Date(millis));
        //SimpleDateFormat sds = new SimpleDateFormat("HH:mm");
        SimpleDateFormat sds = new SimpleDateFormat(DateFormat.TIME_DEFAULT);
        sds.format(c, reusableBuffer, null);
        return reusableBuffer.toString();


Can you please tell em how i should modify this. to get the correct behavior in both cases

BlackBerry Development Advisor
Posts: 15,882
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Need to change time format as per selected on device by user.

From the JavaDocs:






public static final int TIME_DEFAULT
Default time format style.

By default, set to DateFormat.TIME_MEDIUM; subclasses may override this.

This means that TIME_DEFAULT is the same as TIME_MEDIUM.  It is a constant that doesn't change and doesn't reflect what the user has configured on their BlackBerry Smartphone.  There is no API to retrieve this setting.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Posts: 112
Registered: ‎04-28-2010
My Device: 8520
My Carrier: AirTel

Re: Need to changte time format as per selected on device by user.

hello vjava,


use SimpleDateFormat("HH:mm") for 24 hour format, as it results 14:30   of  2:30 pm (12 hour format)


And use SimpleDateFormat("hh:mm aa") for 12 hour format,

as it results 02:30 pm  of 14:30 (24 hour format)

02:30 am of 02:30 (24 hour format)




New Developer
Posts: 21
Registered: ‎12-24-2009
My Device: Not Specified

Re: Need to changte time format as per selected on device by user.

You can create a DateField with the format "DateField.TIME" and then call toString() on the DateField.