Vaadin Grid如果日期是12月31日,则显示错误的年份

发布于 2025-02-02 03:21:57 字数 1230 浏览 2 评论 0原文

我创建了一个vaadin网格,并将setItems方法与返回分页流的自定义JPA存储库结合使用。当网格必须显示特定日期(2019-12-31)的日期时,就会出现问题,它将自动显示“ 31.12.2020”,看起来日期以某种方式跳到了明年。

这里的网格

private Grid<Budget> createGrid() {
        Grid<Budget> grid = new Grid<>(Budget.class, false);
        grid.setPageSize(100);
        grid.setSortableColumns();        
        grid.addColumn(new LocalDateRenderer<>(Budget::getValidfrom, "dd.MM.YYYY")).setHeader("Gültig von");
        grid.addColumn(new LocalDateRenderer<>(Budget::getValidto, "dd.MM.YYYY")).setHeader("Gültig bis");
        for (Grid.Column<Budget> c : grid.getColumns()) {
            c.setAutoWidth(true).setFlexGrow(2);
        }
        return grid;
}

在这里如何填充数据库中的网格

grid.setItems(query -> service.getLimitData(filter, query.getPage(), query.getPageSize()).stream());

数据集

vaadin网格中的数据集

I've created a vaadin grid and used the setItems method in combination with a custom jpa repository that returns a paged stream. The problem appears when the grid has to show a date with a specific date (2019-12-31), it will automatically show "31.12.2020", looks like the date is somehow jumping to the next year.

here the grid

private Grid<Budget> createGrid() {
        Grid<Budget> grid = new Grid<>(Budget.class, false);
        grid.setPageSize(100);
        grid.setSortableColumns();        
        grid.addColumn(new LocalDateRenderer<>(Budget::getValidfrom, "dd.MM.YYYY")).setHeader("Gültig von");
        grid.addColumn(new LocalDateRenderer<>(Budget::getValidto, "dd.MM.YYYY")).setHeader("Gültig bis");
        for (Grid.Column<Budget> c : grid.getColumns()) {
            c.setAutoWidth(true).setFlexGrow(2);
        }
        return grid;
}

here how I fill the grid

grid.setItems(query -> service.getLimitData(filter, query.getPage(), query.getPageSize()).stream());

dataset in database
enter image description here
dataset in vaadin grid
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2025-02-09 03:21:58

tl; dr

更改yyyy to uuuu纠正您的格式模式。

您的问题与 vaadin 无关。日期格式是标准Java。

基于周的年度与日历年

您的格式代码不正确。

大写yyyy是指基于一周的年度,而不是日历年。该代码使用 iso 8601几周的定义 neeks and Base Base and Base Base year 星期一,运行整整7天,第一周包含日历年的第一个星期四。这意味着基于本周的第一周和最后几周可能有几天/下一个日历年的几天。

因此,您遇到的意外一年是一个功能,而不是错误。

tl;dr

Change YYYY to uuuu to correct your formatting pattern.

Your issue has nothing to do with Vaadin specifically. Date formatting is standard Java.

Week-based year versus calendar year

Your formatting code is incorrect.

Uppercase YYYY means a week-based year, not a calendar year. That code uses the ISO 8601 definition of weeks and week-based year: Week starts on Monday, runs a full 7 days, and first week contains the first Thursday of the calendar year. That means the first and last weeks of the week-based year may have a few days from the previous/next calendar year.

So the unexpected year you encountered is a feature, not a bug.

???? For calendar-year, use lowercase yyyy or uuuu.

These formatting pattern codes are documented on the Javadoc for the DateTimeFormatter class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文