0

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.

4

1 回答 1

0

您可以尝试使用 SimpleDateFormat 对象来转换时间格式。

 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();
}

这是 SimpleDateFromat 的 javadoc链接

于 2011-11-05T07:51:31.500 回答