Example usage for java.time.format FormatStyle SHORT

List of usage examples for java.time.format FormatStyle SHORT

Introduction

In this page you can find the example usage for java.time.format FormatStyle SHORT.

Prototype

FormatStyle SHORT

To view the source code for java.time.format FormatStyle SHORT.

Click Source Link

Document

Short text style, typically numeric.

Usage

From source file:dhbw.clippinggorilla.userinterface.windows.PreferencesWindow.java

private Component getTimeRow(User user, LocalTime time) {
    HorizontalLayout layoutTimeRow = new HorizontalLayout();
    layoutTimeRow.setWidth("100%");

    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
    Label labelTime = new Label(time.format(formatter));

    Button buttonDelete = new Button(VaadinIcons.TRASH);
    buttonDelete.addStyleName(ValoTheme.BUTTON_DANGER);
    buttonDelete.setWidth("80px");
    buttonDelete.addClickListener(e -> {
        if (layoutClippingTimes.getComponentCount() > 1) {
            layoutClippingTimes.removeComponent(layoutTimeRow);
            UserUtils.removeClippingSendTime(user, time);
        } else {/*from w w  w  .  j av a2  s . c  o m*/
            VaadinUtils.errorNotification(Language.get(Word.AT_LREAST_ONE_TIME));
        }
    });

    layoutTimeRow.addComponents(labelTime, buttonDelete);
    layoutTimeRow.setComponentAlignment(labelTime, Alignment.MIDDLE_LEFT);
    layoutTimeRow.setComponentAlignment(buttonDelete, Alignment.MIDDLE_CENTER);
    layoutTimeRow.setExpandRatio(labelTime, 5);

    return layoutTimeRow;
}

From source file:jgnash.report.pdf.Report.java

public void addFooter() throws IOException {

    final String timeStamp = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
            .format(LocalDateTime.now());

    final int pageCount = pdfDocument.getNumberOfPages();
    float yStart = getBottomMargin() * 2 / 3;

    for (int i = 0; i < pageCount; i++) {
        final PDPage page = pdfDocument.getPage(i);
        final String pageText = MessageFormat.format(rb.getString("Pattern.Pages"), i + 1, pageCount);
        final float width = getStringWidth(pageText, getFooterFont(), getFooterFontSize());

        try (final PDPageContentStream contentStream = new PDPageContentStream(pdfDocument, page,
                PDPageContentStream.AppendMode.APPEND, true)) {
            contentStream.setFont(getFooterFont(), getFooterFontSize());

            drawText(contentStream, getLeftMargin(), yStart, timeStamp);
            drawText(contentStream, (float) getPageFormat().getWidth() - getRightMargin() - width, yStart,
                    pageText);//w  w  w  . j av a 2s.  c  om
        } catch (final IOException e) {
            logSevere(Report.class, e);
        }
    }
}

From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java

@Override
public String getUsersLocalDateTimeString(Instant date) {
    if (date == null)
        return "";
    ZoneId zone = userTimeService.getLocalTimeZone().toZoneId();
    DateTimeFormatter df = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT)
            .withZone(zone).withLocale(resourceLoader.getLocale());
    return df.format(date);
}

From source file:org.talend.dataquality.statistics.datetime.utils.PatternListGenerator.java

private static List<LocaledPattern> processBaseDateTimePatternsByLocales() {

    // Set<String> dateTimePatternsList = new LinkedHashSet<String>();
    List<LocaledPattern> dateTimePatterns = new ArrayList<LocaledPattern>();

    for (FormatStyle style : FORMAT_STYLES) {
        if (PRINT_DETAILED_RESULTS) {
            System.out.println("--------------------Date Style: " + style + "-----------------------");
        }// ww  w .  j a  v a  2 s  .c  om
        for (Locale locale : localeArray) {
            getFormatByStyle(style, style, true, false, locale, true);// Date Only
        }
    }
    for (FormatStyle style : FORMAT_STYLES) {
        if (PRINT_DETAILED_RESULTS) {
            System.out.println("--------------------DateTime Style: " + style + "-----------------------");
        }
        for (Locale locale : localeArray) {
            getFormatByStyle(style, style, true, true, locale, true); // Date & Time
        }
    }

    // include additional combinations
    for (Locale locale : primaryLocaleArray) {
        getFormatByStyle(FormatStyle.SHORT, FormatStyle.MEDIUM, true, true, locale, false);
        getFormatByStyle(FormatStyle.MEDIUM, FormatStyle.SHORT, true, true, locale, false);
    }

    dateTimePatterns.removeAll(knownPatternList);
    // return new ArrayList<String>(dateTimePatterns);
    return dateTimePatterns;

}

From source file:org.talend.dataquality.statistics.datetime.utils.PatternListGenerator.java

private static void generateDateFormats() throws IOException {
    int currentLocaledPatternSize = 0;
    knownLocaledPatternList.clear();/*  w  ww  .  ja va  2  s .  co  m*/
    knownPatternList.clear();
    // 1. Base Localized DateTimePatterns (java8 DateTimeFormatterBuilder)
    processBaseDateTimePatternsByLocales();
    int basePatternCount = knownLocaledPatternList.size() - currentLocaledPatternSize;
    if (PRINT_DETAILED_RESULTS) {
        System.out.println("#basePatterns = " + basePatternCount + "\n");
    }
    currentLocaledPatternSize = knownLocaledPatternList.size();

    // 2. Other common DateTime patterns
    for (LocaledPattern lp : OTHER_COMMON_PATTERNS_NEED_COMBINATION) {
        addLocaledPattern(lp);

        for (Locale locale : primaryLocaleArray) {

            String patternShort = DateTimeFormatterBuilder.getLocalizedDateTimePattern(//
                    null, FormatStyle.SHORT, IsoChronology.INSTANCE, locale);//
            LocaledPattern combinedShortLP = new LocaledPattern(lp.pattern + " " + patternShort, locale,
                    FormatStyle.SHORT.name(), true);
            addLocaledPattern(combinedShortLP);

            String patternMedium = DateTimeFormatterBuilder.getLocalizedDateTimePattern(//
                    null, FormatStyle.MEDIUM, IsoChronology.INSTANCE, locale);//
            LocaledPattern combinedMediumLP = new LocaledPattern(lp.pattern + " " + patternMedium, locale,
                    FormatStyle.MEDIUM.name(), true);
            addLocaledPattern(combinedMediumLP);

        }

    }

    for (LocaledPattern lp : OTHER_COMMON_PATTERNS) {
        addLocaledPattern(lp);
    }

    // 3. ISO and RFC DateTimePatterns
    processISOAndRFCDateTimePatternList();
    // knownPatternList.addAll(isoPatternList);
    int isoPatternCount = knownLocaledPatternList.size() - currentLocaledPatternSize;
    if (PRINT_DETAILED_RESULTS) {
        System.out.println("#DateTimePattern(ISO&RFC) = " + isoPatternCount + "\n");
    }
    currentLocaledPatternSize = knownLocaledPatternList.size();

    // 4. Additional Localized DateTimePatterns (java8 DateTimeFormatterBuilder)
    processAdditionalDateTimePatternsByLocales();
    // knownPatternList.addAll(additionalPatternList);
    int additionalPatternCount = knownLocaledPatternList.size() - currentLocaledPatternSize;
    if (PRINT_DETAILED_RESULTS) {
        System.out.println("#additionalPatternList = " + additionalPatternCount + "\n");
    }
    currentLocaledPatternSize = knownLocaledPatternList.size();

    if (PRINT_DETAILED_RESULTS) {
        System.out.println("#Total = " + knownLocaledPatternList.size() + //
                " (#baseDatePatterns = " + basePatternCount + //
                ", #isoPatterns = " + isoPatternCount + //
                ", #additionalPatterns = " + additionalPatternCount + ")\n");//
    }

    // table header
    dateSampleFileTextBuilder.append("Sample\tPattern\tLocale\tFormatStyle\tIsWithTime\n");

    RegexGenerator regexGenerator = new RegexGenerator();
    for (LocaledPattern lp : knownLocaledPatternList) {

        datePatternFileTextBuilder.append(lp).append("\n");

        String regex = regexGenerator.convertPatternToRegex(lp.pattern);
        dateRegexFileTextBuilder.append(lp.getPattern()).append("\t^").append(regex).append("$\n");
        dateSampleFileTextBuilder
                .append(ZONED_DATE_TIME.format(DateTimeFormatter.ofPattern(lp.getPattern(), lp.getLocale())))
                .append("\t").append(lp.getPattern())//
                .append("\t").append(lp.getLocale())//
                .append("\t").append(lp.getFormatStyle())//
                .append("\t").append(lp.isWithTime()).append("\n");
    }

    // Date Formats
    String path = SystemDateTimePatternManager.class.getResource("DateFormats.txt").getFile().replace(
            "target" + File.separator + "classes",
            "src" + File.separator + "main" + File.separator + "resources");
    IOUtils.write(datePatternFileTextBuilder.toString(), new FileOutputStream(new File(path)));

    // Date Regexes
    path = SystemDateTimePatternManager.class.getResource("DateRegexes.txt").getFile().replace(
            "target" + File.separator + "classes",
            "src" + File.separator + "main" + File.separator + "resources");
    IOUtils.write(dateRegexFileTextBuilder.toString(), new FileOutputStream(new File(path)));

    // Date Samples
    path = SystemDateTimePatternManager.class.getResource("DateSampleTable.txt").getFile().replace(
            "target" + File.separator + "classes",
            "src" + File.separator + "test" + File.separator + "resources");
    IOUtils.write(dateSampleFileTextBuilder.toString(), new FileOutputStream(new File(path)));

    // generate grouped Date Regexes
    FormatGroupGenerator.generateDateRegexGroups();
}