Skip to Content

Compare two Java Date objects using before method example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.   Compare two Java Date objects using before method example.
  3.   This example shows how to compare two java Date objects using before method of
  4.   java Date Class.
  5. */
  6.  
  7. import java.util.Date;
  8.  
  9. public class CompareDateUsingBeforeExample{
  10.  
  11.   public static void main(String[] args) {
  12.    
  13.     //create first date object
  14.     Date d1 = new Date();
  15.  
  16.     //make interval of 10 millisecond before creating second date object    
  17.     try{
  18.       Thread.sleep(10);
  19.     }catch(Exception e){
  20.     }
  21.    
  22.    
  23.     //create second date object
  24.     Date d2 = new Date();
  25.    
  26.     //use boolean before(Date anotherDate) method of Date Class to
  27.     //check whether a date is before the specified date
  28.    
  29.     System.out.println("First Date : " + d1);
  30.     System.out.println("Second Date : " + d2);
  31.     System.out.println("Is first date before second ? : " + d1.before(d2));    
  32.  
  33.   }
  34. }
  35.  
  36. /*
  37. TYPICAL Output Would be
  38. First Date : Sun Sep 09 19:40:44 EDT 2007
  39. Second Date : Sun Sep 09 19:40:44 EDT 2007
  40. Is first date before second ? : true
  41. */