title: how to validate the timestamp (yyyy-MM-dd HH:mm:ss) and (yyyy-MM-dd)
body: <p>User will enter the Date like <code>yyyy-MM-dd</code> or  <code>yyyy-MM-dd hh:mm:ss</code>.Then I need to validate the timestamp. please help me on this.</p>
  
  <p>I need to verify these type of validations of Both (yyyy-MM-dd) or (yyyy-MM-dd hh:mm:ss).
  If the user enters the date is yyyy-MM-dd then will take the like this yyyy-MM-dd 00:00:00 and else if user enters the date is yyyy-MM-dd HH:mm:ss then take as it is like  yyyy-MM-dd HH:mm:ss   </p>
  
  <pre><code> private static boolean dateValidate(String inputDate) {
                  try {
                      String[] datePattern = {"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd "};
                      for (String pattern : datePattern) {
                          SimpleDateFormat sdf = new SimpleDateFormat(pattern);
                          Date date = sdf.parse(inputDate);
                          String formattedDate = sdf.format(date);
                          if (inputDate.equals(formattedDate)) {
                              return true;
                          }
                      }
                  } catch (ParseException ex) {
                      return false;
                  }
                  return false;
  
              }
              public static void main(String args[]) {
                  // TODO Auto-generated method stub
                  System.out.println(SampleTest.dateValidate("2014-02-22 22:23:22"));
                  System.out.println(SampleTest.dateValidate("2014-02-22"));
  
  
              }
  </code></pre>