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

Android examples for java.util:Date Format

Description

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

    /**/*from  ww  w  .ja  v a2 s .  co m*/
     * Return date in year format in device locale.
     *
     * @param date
     * @return formated date eg : "2015" "2016" etc.
     */
    public static String formatDateInYearRepresentation(
            @NonNull final Date date) {
        final String parsedDate = YEAR_FORMAT.format(date);
        return parsedDate;
    }
}

Related Tutorials