Return date in month, day of month and year format in device locale - Android java.util

Android examples for java.util:Month

Description

Return date in month, day of month and year format in device locale

Demo Code


//package com.java2s;
import android.support.annotation.NonNull;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    private static final SimpleDateFormat MONTH_DATE_YEAR_FORMAT = new SimpleDateFormat(
            "MMM d yyyy", Locale.getDefault());

    /**/*  w  w  w.j av  a  2 s  . c om*/
     * Return date in month, day of month and year format in device locale
     *
     * @param date
     * @return formated date eg : "JAN 1 2016" etc.
     */
    public static String formatDateInMonthDateYearRepresentation(
            @NonNull final Date date) {
        String parsedDate = MONTH_DATE_YEAR_FORMAT.format(date);
        if (parsedDate != null) {
            parsedDate = parsedDate.toUpperCase();
        }
        return parsedDate;
    }
}

Related Tutorials