我在 java 中做了一个应用程序,其中我有“从日期”和“到日期”的表单。我想检查从“To date”中选择的日期是否在“From date”之后 示例:如果从“From date”中选择的日期是 2013-03-18(YY-mm-dd) 那么选择的日期是“迄今为止”应该是 2013-03-18 之后/之后的任何日期。要获取我使用 JXDatePicker 的日期,并将日期转换为我使用的 yy-mm-dd 格式,
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy/MM/dd")
我需要这个来验证,所以如果“To date”是>“From date”,那么它应该显示 JOptionPane错误信息。
编辑>我尝试从 JXDatePicker 中获取日期
Date fd = (Date) from.getDate();
这是在从 JXDatePicker 选择日期时执行的,我也尝试过打印日期,但是当我运行应用程序时出现如下错误:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Date
at rejectionCategorisedReport$1.actionPerformed(rejectionCategorisedReport.java:154)
at org.jdesktop.swingx.JXDatePicker.fireActionPerformed(JXDatePicker.java:916)
at org.jdesktop.swingx.JXDatePicker.commitEdit(JXDatePicker.java:706)
at org.jdesktop.swingx.plaf.basic.BasicDatePickerUI.commit(BasicDatePickerUI.java:859)
at org.jdesktop.swingx.plaf.basic.BasicDatePickerUI$Handler.monthViewActionPerformed(BasicDatePickerUI.java:1327)
at org.jdesktop.swingx.plaf.basic.BasicDatePickerUI$Handler.actionPerformed(BasicDatePickerUI.java:1302)
at org.jdesktop.swingx.JXMonthView.fireActionPerformed(JXMonthView.java:1788)
at org.jdesktop.swingx.JXMonthView.commitSelection(JXMonthView.java:1686)
at org.jdesktop.swingx.plaf.basic.BasicMonthViewUI$Handler.mouseReleased(BasicMonthViewUI.java:2053)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
有人可以帮助我并告诉我问题是什么吗?