List of usage examples for java.util Date equals
public boolean equals(Object obj)
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); // 15-04-2012 calendar.set(Calendar.DAY_OF_MONTH, 15); calendar.set(Calendar.YEAR, 2012); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MONTH, 3); Date start = calendar.getTime(); // 15-06-2012 calendar.set(Calendar.MONTH, 5); Date end = calendar.getTime(); calendar.setTime(start);// w ww .j a va 2 s . c o m Date d = null; while ((d = calendar.getTime()).before(end) || d.equals(end)) { int day = calendar.get(Calendar.DAY_OF_WEEK); if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) { System.out.println(d); } calendar.add(Calendar.DAY_OF_MONTH, 1); } }
From source file:Main.java
public static void main(String[] argv) { Object activeValue = new UIDefaults.ActiveValue() { public Object createValue(UIDefaults table) { return new Date(); }/*from ww w . j a v a 2 s .c o m*/ }; UIManager.put("key", activeValue); Date d1 = (Date) UIManager.get("key"); Date d2 = (Date) UIManager.get("key"); boolean b = d1.equals(d2); // false }
From source file:Main.java
public static void main(String[] args) { Date date = new Date(); Date date2 = new Date(); // Check if they are equal boolean check = date.equals(date2); // print the result System.out.println("Dates are equal:" + check); }
From source file:MainClass.java
public static void main(String[] a) throws Exception { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = df.parse("2001-01-01"); Date d2 = df.parse("2000-01-01"); String relation;/*from w w w.ja va 2 s . c o m*/ if (d1.equals(d2)) relation = "the same date as"; else if (d1.before(d2)) relation = "before"; else if (d1.after(d2)) relation = "after"; System.out.println(d1 + " is " + relation + ' ' + d2); }
From source file:CompareDates.java
public static void main(String[] args) throws ParseException { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // Get Date 1 Date d1 = df.parse("2000-02-01"); // Get Date 2 Date d2 = df.parse("2001-03-02"); String relation;/*from w ww . j a v a2 s . c om*/ if (d1.equals(d2)) relation = "the same date as"; else if (d1.before(d2)) relation = "before"; else relation = "after"; System.out.println(d1 + " is " + relation + ' ' + d2); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { Date date = new Date(); Thread.sleep(1);//from ww w .j a v a 2s.com Date other = new Date(); out.printf("equals? = %s, hashCode? = %s %n", (date.equals(other)), (date.hashCode() == other.hashCode())); Date todayeOne = trim(date); Date todayTwo = trim(other); out.printf("equals? = %s, hashCode? = %s %n", (todayeOne.equals(todayTwo)), (todayeOne.hashCode() == todayTwo.hashCode())); }
From source file:Main.java
public static void main(String[] args) { Calendar someTime = Calendar.getInstance(); someTime.set(Calendar.HOUR_OF_DAY, 17); someTime.set(Calendar.MINUTE, 0); someTime.set(Calendar.SECOND, 0); // convert it to java epoch date Date someDate = toEpochDate(someTime); // create a date object from java.sql.Time Date fromSqlTime = new Date(Time.valueOf("17:00:00").getTime()); // now do the comparison System.out.println("Some Date: " + someDate.toString()); System.out.println("Sql Time: " + fromSqlTime.toString()); System.out.println("Are they equal? " + someDate.equals(fromSqlTime)); }
From source file:Main.java
public static void main(String[] args) { try {/*from w ww . j av a2 s . co m*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date1 = sdf.parse("2015-12-31"); Date date2 = sdf.parse("2015-01-31"); System.out.println(sdf.format(date1)); System.out.println(sdf.format(date2)); if (date1.after(date2)) { System.out.println("Date1 is after Date2"); } if (date1.before(date2)) { System.out.println("Date1 is before Date2"); } if (date1.equals(date2)) { System.out.println("Date1 is equal Date2"); } } catch (ParseException ex) { ex.printStackTrace(); } }
From source file:Main.java
/** * Tests if the given base date is strictly between the given start date and * end date./* www . j ava2s. co m*/ * * @param baseDate the date used as base for the test. * @param startDate the start date. * @param endDate the end date. * @return <code>true</code> if the base date is between the start date * and end date, <code>false</code> otherwise. */ public static boolean strictlyBetween(Date baseDate, Date startDate, Date endDate) { if (startDate.equals(endDate) || endDate.before(startDate)) { return false; } if (startDate.before(baseDate) && endDate.after(baseDate)) { return true; } return false; }
From source file:Main.java
/** * Tests if the given base date is between the given start date and end * date, including the dates themselves. * * @param baseDate the date used as base for the test. * @param startDate the start date.// www.jav a 2 s . c o m * @param endDate the end date. * @return <code>true</code> if the base date is between the start date * and end date, <code>false</code> otherwise. */ public static boolean between(Date baseDate, Date startDate, Date endDate) { if (startDate.equals(endDate) || endDate.before(startDate)) { return false; } if ((startDate.before(baseDate) || startDate.equals(baseDate)) && (endDate.after(baseDate) || endDate.equals(baseDate))) { return true; } return false; }