String s = "12:18:00";
DateFormat f1 = new SimpleDateFormat("hh:mm:ss");
Date d = f1.parse(s);
DateFormat f2 = new SimpleDateFormat("h:mma");
f2.format(d).toLowerCase(); // "12:18am"
Run Code Online (Sandbox Code Playgroud)
尝试了上述方法,但它在晚上 11:18 返回?
也许你可以做这样的事情:
final String time = "12:18:00";
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();
}
Run Code Online (Sandbox Code Playgroud)
取自这里。
归档时间: |
|
查看次数: |
7247 次 |
最近记录: |