parsecer parsecer - 14 days ago 5
Java Question

Java SimpleDateFormat question marks instead of Month

I want to display the current month, date, year and time.
I have a .jsp file which has the following code inside:

SimpleDateFormat format = new SimpleDateFormat("MMM dd,yyyy hh:mm");
String date = format.format(new Date());


The output on the page is:

??? 13,2016 04:14

So, the month isn't displayed.
But when I use
instead of
it works:

10 13,2016 04:17

But I need a full name of the month, and neither
works. The
gives the similar output:

??????? 13,2016 04:18

How can I fix that?


Try SimpleDateFormat("MMM dd,yyyy hh:mm",Locale.US).

If you are trying to print date in a foriegn locale (or if your locale seems to be wrong), you can change change it in your environment so that it can generate the name of the month correctly.

You can set your system locale in Windows using control panel like Start->Control Panel->Clock,Language and Region like shown here. You can also change locale per user as discussed in this detailed FAQ

If you are on linux, you can set your locale in system configuration OR in your HOME directory as discussed here