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

Android examples for java.util:Month

Description

Return date in 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_YEAR_FORMAT = new SimpleDateFormat(
            "MMM yyyy", Locale.getDefault());

    /**//from   www .  ja va2 s  .  c  o m
     * Return date in month and year format in device locale
     *
     * @param date
     * @return formated date eg : "JAN 2016" "FEB 2015" etc.
     */
    public static String formatDateInMonthYearRepresentation(
            @NonNull final Date date) {
        String parsedDate = MONTH_YEAR_FORMAT.format(date);
        if (parsedDate != null) {
            parsedDate = parsedDate.toUpperCase();
        }
        return parsedDate;
    }
}

Related Tutorials