Example usage for java.time Month getDisplayName

List of usage examples for java.time Month getDisplayName

Introduction

In this page you can find the example usage for java.time Month getDisplayName.

Prototype

public String getDisplayName(TextStyle style, Locale locale) 

Source Link

Document

Gets the textual representation, such as 'Jan' or 'December'.

Usage

From source file:Main.java

public static void main(String[] args) {
    Month m = Month.from(LocalDate.now());

    System.out.println(m.getDisplayName(TextStyle.SHORT, Locale.UK));

}

From source file:org.efaps.esjp.common.uiform.Field_Base.java

/**
 * @param _parameter    Parameter as passed from the eFaps API
 * @return Return containing Html Snipplet
 * @throws EFapsException on error/* w  ww  .j a  v a2 s  .c  om*/
 */
public Return getOptionList4DateTime(final Parameter _parameter) throws EFapsException {
    final List<DropDownPosition> positions = new ArrayList<>();
    final String dateFieldType = getProperty(_parameter, "DateFieldType", "YEAR");
    switch (dateFieldType) {
    case "MONTH":
        for (final Month month : Month.values()) {
            final DropDownPosition pos = getDropDownPosition(_parameter, month.getValue(),
                    month.getDisplayName(TextStyle.FULL, Context.getThreadContext().getLocale()));
            pos.setSelected(month.getValue() == new DateTime().getMonthOfYear());
            positions.add(pos);
        }
        break;
    case "YEAR":
    default:
        final String fromStr = getProperty(_parameter, "From", "-10");
        final String toStr = getProperty(_parameter, "To", "+10");
        LocalDate start;
        if (StringUtils.isNumeric(fromStr)) {
            start = LocalDate.of(Integer.parseInt(fromStr), 1, 1);
        } else {
            start = LocalDate.now().plusYears(Integer.parseInt(fromStr));
        }
        final LocalDate end;
        if (StringUtils.isNumeric(toStr)) {
            end = LocalDate.of(Integer.parseInt(toStr), 1, 1);
        } else {
            end = LocalDate.now().plusYears(Integer.parseInt(toStr));
        }
        while (start.isBefore(end)) {
            final DropDownPosition pos = getDropDownPosition(_parameter, start.getYear(), start.getYear());
            pos.setSelected(start.getYear() == new DateTime().getYear());
            positions.add(pos);
            start = start.plusYears(1);
        }
        break;
    }
    final Return ret = new Return();
    ret.put(ReturnValues.VALUES, positions);
    return ret;
}