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

Android examples for java.util:Month

Description

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

    /**/*from   w  w w .jav a 2  s  . co m*/
     * Return date in month format in device locale.
     *
     * @param date
     * @return formated date eg : "JAN" "FEB" etc
     */
    public static String formatDateInMonthRepresentation(
            @NonNull final Date date) {
        String parsedDate = MONTH_FORMAT.format(date);
        if (parsedDate != null) {
            parsedDate = parsedDate.toUpperCase();
        }
        return parsedDate;
    }
}

Related Tutorials