display current time in android application on HTC wildfire

273 Views Asked by At

I have created a basic app, which shows current timings using the following code

String currentime = dateFormat.getTimeInstance().format(new Date());

It works perfect on the emulator eg. 10:25:00 AM, whereas in HTC wildfire it displays as 10:25:00 missing the AM/PM. could anybody help me on this.

1

There are 1 best solutions below

2
On

you can try using a SimpleDateFormat object to convert the time formats.

 final String time = "23:15";

try {
    final SimpleDateFormat sdf = new SimpleDateFormat("H:mm");
    final Date dateObj = sdf.parse(time);
    System.out.println(dateObj);
    System.out.println(new SimpleDateFormat("K:mm").format(dateObj));
} catch (final ParseException e) {
    e.printStackTrace();
}

here is the javadoc link for SimpleDateFromat.