title: How to find previous date if current date is given as a String?
body: <p>How to find previous date if current date is given as a String? Below is given my code. Is there any shorter solution?</p>
  
  <pre><code>   private static String previousDay(String date) {
          String[] ymd = date.split("-");
          int year = Integer.parseInt(ymd[0]);
          int month = Integer.parseInt(ymd[1]);
          int day = Integer.parseInt(ymd[2]);
          String newDate = "";
          if (day &gt; 1 &amp; month &gt; 1)
              newDate = year+"-"+month+"-"+(day-1);
          else if (day == 1 &amp; month &gt; 1) {
              Calendar calendar = new GregorianCalendar(year,month-1, 1);
              int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
              newDate = year+"-"+(month-1)+"-"+daysInMonth;
          } else if (day == 1 &amp; month == 1) {
              Calendar calendar = new GregorianCalendar(year,12, 1);
              int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
              newDate = year+"-"+12+"-"+daysInMonth;
          }
          return newDate;
      }
  </code></pre>