开发者

Capital letter in SimpleDateFormat

executing this piece of code:

SimpleDateFormat sdfIn = new SimpleDateFormat("yyyy-MM-dd");
                            Date date = null;
                            try {
                                date = sdfIn.parse(value11);
                            } catch (ParseException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            SimpleDateFormat sdfOut = new SimpleDateFormat("MMM d, yyyy");

                            System.out.println(sdfOut.format( date ));

I an getting this output nov 23, 2005 instead of Nov 23, 2005开发者_StackOverflow which would be much better.

Does anybody knows how to change it?? Thanks in advance


The exact strings that get generated depend on the locale you're in. If you just use

new SimpleDateFormat("MMM d, yyyy");

then the system default locale will be used. Your default locale probably renders the month as nov rather than Nov.

if you want a specific locale to be used, pass it in to the constructor, e.g.

new SimpleDateFormat("MMM d, yyyy", Locale.US);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜