如何比较到期日与今天的日期?

问题描述 投票:0回答:1

我正在尝试使用过期日期表中的 LocalDate 来比较两个日期。问题是我无法根据 dateExpiry 正确设置行格式这应该是这样的:enter image description here

                if(today.isEqual(LocalDate.parse(medicament))){
                    currentRow.setStyle("-fx-background-color:tomato");

                } else if (today.before(LocalDate.parse(medicament).plusMonths(3))) {

                    currentRow.setStyle("-fx-background-color:orange");

                    
                } else {
                    currentRow.setStyle("-fx-background-color:lightgreen");
                }

如何正确设置单元格格式

javafx
1个回答
0
投票

导入java.time.LocalDate;

public class ExpireDateTable {
    public static void main(String[] args) {
        // Sample dates
        LocalDate currentDate

= LocalDate.now(); 本地日期日期到期 = LocalDate.of(2024, 2, 28); // 例子 有效期

        // Comparing dates and applying row formatting
        if (dateExpiry.isBefore(currentDate)) {
            System.out.println("Row formatting: Date expired, apply formatting for past expiry date.");
            // Apply formatting for past expiry date
        } else if (dateExpiry.isEqual(currentDate)) {
            System.out.println("Row formatting: Date expiring today, apply formatting accordingly.");
            // Apply formatting for expiry date today
        } else {
            System.out.println("Row formatting: Date is in the future, no special formatting needed.");
            // Apply default formatting
        }
    }
} 
© www.soinside.com 2019 - 2024. All rights reserved.