Displaying AM and PM in lower case after date formatting

xrcwrn picture xrcwrn · Nov 27, 2012 · Viewed 53.1k times · Source

After formatting a datetime, the time displays AM or PM in upper case, but I want it in lower case like am or pm.

This is my code:

public class Timeis {
    public static void main(String s[]) {
        long ts = 1022895271767L;
        String st = null;  
        st = new SimpleDateFormat(" MMM d 'at' hh:mm a").format(ts);
        System.out.println("time is " + ts);  
    }
}

Answer

James Jithin picture James Jithin · Nov 27, 2012

This works

public class Timeis {
    public static void main(String s[]) {
        long ts = 1022895271767L;
        SimpleDateFormat sdf = new SimpleDateFormat(" MMM d 'at' hh:mm a");
        // CREATE DateFormatSymbols WITH ALL SYMBOLS FROM (DEFAULT) Locale
        DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
        // OVERRIDE SOME symbols WHILE RETAINING OTHERS
        symbols.setAmPmStrings(new String[] { "am", "pm" });
        sdf.setDateFormatSymbols(symbols);
        String st = sdf.format(ts);
        System.out.println("time is " + st);
    }
}