在SimpleDateFormat中使用a和aaa有什么区别 [英] Whats the difference in using a and aaa in SimpleDateFormat

查看:326
本文介绍了在SimpleDateFormat中使用a和aaa有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将当前日期显示为 00:50:32 A



这是我的代码

p>

  Date date = new Date(); 
SimpleDateFormat sdf = new SimpleDateFormat(HH:mm:ss a);
String time = sdf.format(date);
System.out.println(time:+ time);

但是打印为:

<$ p $ time:00:50:32 AM

c $ c> HH:mm:ss a 和 HH:mm:ss aaa ,但结果相同。

解决方案

不能做!如果模式是4个字母或更少,使用短格式。所以'a','aa','aaa'和'aaaa'是完全相同的。

所有你能做的就是把它格式化为a A'或'P'。

话虽如此,使用'HH'(24小时制)为什么你需要上午/下午? b $ b

I want to display current date as 00:50:32 A

Here is my code

Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss a");
String time = sdf.format(date);
System.out.println("time : " + time);

But it print as:

time : 00:50:32 AM

I tried both HH:mm:ss a and HH:mm:ss aaa, but results are the same.

解决方案

Can't do! If the pattern is 4 letters or less, short format is used. So 'a', 'aa', 'aaa' and 'aaaa' are identical.

All you can do is to format it without 'a', and add 'A' or 'P' manually.

Having said that, using 'HH' (24-hours clock) why would you need AM/PM?

这篇关于在SimpleDateFormat中使用a和aaa有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆