get Date Time Hour Pattern With Am Pm - Java java.util

Java examples for java.util:Date Parse

Description

get Date Time Hour Pattern With Am Pm

Demo Code


import java.io.Serializable;
import java.util.Locale;

public class Main{
    static final String timeFormat12HourWithAmAndPm = "hh:mm aa";
    public static String getDateTime12HourPatternWithAmPm(Locale locale) {
        String pattern = getDatePattern(locale);
        pattern = pattern + " " + timeFormat12HourWithAmAndPm;
        return pattern;
    }/*from w  ww . jav a2s  . c o  m*/
    public static String getDatePattern(Locale locale) {
        // Get ISO standard pattern with formatted (DD, MM, YYYY)
        if (locale != null && locale.toString().equalsIgnoreCase("zh_HK")) {
            locale = new Locale("zh", "CN");
        }
        DateFormatProperties props = new DateFormatProperties();
        props.setDateStyle("short");
        props.setLocale(locale);
        props.setTimeStyle("HH:mm:ss");

        CustomDateFormatter customFormatter = new CustomDateFormatter(props);
        return customFormatter.getDatePattern();
    }
}

Related Tutorials