Advertisement
Guest User

Untitled

a guest
May 27th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. //CHECAR A VALIDADE DA DATA
  2.  
  3.  
  4. private boolean checkDate(int day, int month, int year){ //Vê se a data é válida
  5.            
  6.         //year restriction here
  7.             if (0 >= day | day > 31) return false;
  8.             if (0 >= month | month > 12) return false;
  9.             if (month == 4 | month == 6 | month == 9 | month == 11)
  10.                 if (day == 31) return false;
  11.             if (month == 2){
  12.                 if (checkLeapYear(year))
  13.                     if (day > 29) return false;
  14.                 else
  15.                     if (day > 28) return false;                    
  16.             }      
  17.             return true;
  18.         }
  19.        
  20.        
  21.         private boolean checkLeapYear(int year){ //Vê se o ano é bissexto
  22.        
  23.             if (year % 4 != 0) return false;
  24.             if (year % 100 != 0) return true;
  25.             return year % 400 == 0;        
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement