开发者

What is wrong with my date format?

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


I suspect you want a format of

hh:mmaa MM/dd/yyyy

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.


Try changing HH:mmaa MM/dd/yyyy to KK:mmaa MM/dd/yyyy. (KK is hour in am/pm, 0-11)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜