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

com.marvinlabs.widget.floatinglabel.instantpicker.JavaTimePrinter 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 JavaTimePrinter implements TimePrinter {

    final DateFormat timeFormat;

    /**
     * Constructor
     *
     * @param timeStyle one of DateFormat's SHORT, MEDIUM, LONG, FULL, or DEFAULT.
     */
    public JavaTimePrinter(int timeStyle) {
        this.timeFormat = DateFormat.getTimeInstance(timeStyle);
    }

    @Override
    public String print(TimeInstantT timeInstant) {
        if (timeInstant == null) return "";

        Calendar cal = new GregorianCalendar(0, 0, 0, timeInstant.getHourOfDay(), timeInstant.getMinuteOfHour(), timeInstant.getSecondOfMinute());
        return timeFormat.format(cal.getTime());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy