我的日期格式有什么问题?
我正在尝试以“time”格式获取日期:“05:09pm 08/02/2011”。到目前为止我所拥有的是
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(
"HH:mmaa MM/dd/yyyy");
holder.put("time", sdf.format(c.getTime()));
,这就是结果。
"time":"21:28PM 08\/26\/2011"
为什么会发生这种情况以及我可以采取什么措施来解决它?谢谢
I am trying to get the date in this format "time":"05:09pm 08/02/2011". What I have so far is
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(
"HH:mmaa MM/dd/yyyy");
holder.put("time", sdf.format(c.getTime()));
and this is what comes out.
"time":"21:28PM 08\/26\/2011"
Why is this happening and what can I do to fix it? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您想要的格式
为
hh
是 01-12 范围内的 12 小时格式。我发现这就是人类代表 12 小时值的典型方式。当然,如果你想要00-11,请按照MByD的建议使用KK。(大写形式是 24 小时版本的 HH,而小写形式是 24 小时版本的 kk,其基本原理是什么,我不知道......)
如果您担心中的反斜杠输出,我怀疑这只是 JSON 转义。我很惊讶它对于正斜杠是必要的,但它不应该造成任何伤害。
I suspect you want a format of
As
hh
is the 12-hour format in the range 01-12. I find that's typically how humans represent 12-hour values. Of course if you want 00-11, use KK instead as suggested by MByD.(Quite what the rationale is for the capitalized form being the 24-hour version of HH, but the lower case form being the 24-hour version of kk, I don't know...)
If you were worried by the backslashes in the output, I suspect that's just JSON-escaping. I'm surprised it's necessary for forward-slashes, but it shouldn't do any harm.
尝试将
HH:mmaa MM/dd/yyyy
更改为KK:mmaa MM/dd/yyyy
。 (KK
是 am/pm 的时间,0-11)Try changing
HH:mmaa MM/dd/yyyy
toKK:mmaa MM/dd/yyyy
. (KK
is hour in am/pm, 0-11)