date string is showing question marks

Viewed 1780

I am using Eclipse 4.5.1 Mars. I have a very simple program which just use Hindi as locale and print out the date in a format:

enter image description here

But when run it, the console print out question marks. But if I remove the Hindi locale, it prints out correct date string. Why? How to fix the question mark problem?

====== CODE BELOW ========

public static void main(String[] args) {
        Locale.setDefault(new Locale("hi", "IN"));
        Calendar calendar = new GregorianCalendar(TimeZone.getDefault(),  Locale.getDefault());
        // print out date string in console
        System.out.println(getDateStr(calendar.getTime()));

    }

    public static String getDateStr(Date date) {
        SimpleDateFormat sdf =  new SimpleDateFormat("yyyy-MM-dd");
        sdf.setTimeZone(TimeZone.getDefault());
        return sdf.format(date);
    }
3 Answers

In Eclipse default text file encoding is Cp1252, update that to UTF-8.
Go to preferences -> General -> Workspace update Text file encoding to UTF-8

Related