All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marvinlabs.widget.floatinglabel.instantpicker.JavaDatePrinter Maven / Gradle / Ivy

The newest version!
package com.marvinlabs.widget.floatinglabel.instantpicker;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * A default implementation using the java.util.DateFormat class with the default locale
 */
public class JavaDatePrinter implements DatePrinter {

    final DateFormat dateFormat;

    /**
     * Constructor
     *
     * @param dateStyle one of DateFormat's SHORT, MEDIUM, LONG, FULL, or DEFAULT.
     */
    public JavaDatePrinter(int dateStyle) {
        this.dateFormat = DateFormat.getDateInstance(dateStyle);
    }

    @Override
    public String print(DateInstant dateInstant) {
        if (dateInstant == null) return "";

        Calendar cal = new GregorianCalendar(dateInstant.getYear(), dateInstant.getMonthOfYear() + 1, dateInstant.getDayOfMonth());
        return dateFormat.format(cal.getTime());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy