java.util.Date.before()とafter()で日付の前後を比較する
package com.arkgame.demopro; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class BeforeAfterDemo { public static void main(String[] args) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); try { Date strA = dateFormat.parse("2019/03/18"); Date strB = dateFormat.parse("2019/03/19"); System.out.println("before()の結果:" + strA.before(strB)); System.out.println("after()の結果:" + strA.after(strB)); } catch (ParseException e) { e.printStackTrace(); } } }
before()の結果:true
after()の結果:false