Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 which would be much better.
Does anybody knows how to change it?? Thanks in advance

like image 444
Blanca Hdez Avatar asked Oct 21 '25 04:10

Blanca Hdez


1 Answers

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);
like image 89
skaffman Avatar answered Oct 22 '25 19:10

skaffman