Capital letter in SimpleDateFormat

execution of 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 get this output nov 23, 2005instead nov 23, 2005, which will be much better.
Does anyone know how to change it? thanks in advance

+3
source share
1 answer

The exact lines that are generated depend on the locale you are in. If you just use

new SimpleDateFormat("MMM d, yyyy");

then the default language system will be used. Your default language probably makes the month like nov, rather than nov.

if you want a specific language to be used, pass it to the constructor, for example

new SimpleDateFormat("MMM d, yyyy", Locale.US);
+10
source

Source: https://habr.com/ru/post/1792499/


All Articles