Code example for Date

Methods: getMinutes, getMonth

0
    @SuppressWarnings("nls") 
    public static String getTimeString(Context context, Date date, boolean excludeZeroMinutes) {
        String value;
        if (is24HourFormat(context)) {
            value = "H:mm";
        } else if (date.getMinutes() == 0 && excludeZeroMinutes){
            value = "h a";
        } 
        else { 
            value = "h:mm a";
        } 
        return new SimpleDateFormat(value).format(date);
    } 
 
    public static String getTimeString(Context context, Date date) {
        return getTimeString(context, date, true);
    } 
 
    /* Returns true if search string is in sortedValues */ 
 
    private static boolean arrayBinaryContains(String search, String... sortedValues) {
        return Arrays.binarySearch(sortedValues, search) >= 0;
    } 
 
    /** 
     * @param context android context 
     * @param date date to format 
     * @return date, with month, day, and year 
     */ 
    @SuppressWarnings("nls") 
    public static String getDateString(Context context, Date date, boolean includeYear) {
        String month = DateUtils.getMonthString(date.getMonth() +
                Calendar.JANUARY, DateUtils.LENGTH_MEDIUM);
        String value;
        String standardDate;
        // united states, you are special 
        Locale locale = Locale.getDefault();
        if (arrayBinaryContains(locale.getLanguage(), "ja", "ko", "zh")
                || arrayBinaryContains(locale.getCountry(),  "BZ", "CA", "KE", "MN" ,"US"))
            value = "'#' d'$'";
        else 
            value = "d'$' '#'";
        if (includeYear)
            value += ", yyyy";
        if (arrayBinaryContains(locale.getLanguage(), "ja", "zh")){
            standardDate = new SimpleDateFormat(value).format(date).replace("#", month).replace("$", "\u65E5"); //$NON-NLS-1$
        }else if ("ko".equals(Locale.getDefault().getLanguage())){
            standardDate = new SimpleDateFormat(value).format(date).replace("#", month).replace("$", "\uC77C"); //$NON-NLS-1$
        }else{ 
            standardDate = new SimpleDateFormat(value).format(date).replace("#", month).replace("$", "");
        } 
        return standardDate;}
 
    public static String getDateString(Context context, Date date) {
        return getDateString(context, date, true);