title: minus 1 hour to DateTime using Joda Time
body: <p>I just want to subtract 1 hour from a <code>DateTime</code> I tried looking it up on Google and I found that there is a method called minus that takes a copy of the date and take a specific duration right here: <a href="http://www.joda.org/joda-time/apidocs/org/joda/time/DateTime.html#minus(long)" rel="noreferrer">http://www.joda.org/joda-time/apidocs/org/joda/time/DateTime.html#minus(long)</a></p>
  
  <p>But I don't know how to use it and I can't an find a example on the internet. </p>
  
  <p>Here's my code: </p>
  
  <pre><code>String string1 = (String) table_4.getValueAt(0, 1);
      String string2= (String) table_4.getValueAt(0, 2);
  
      DateTimeFormatter dtf = DateTimeFormat.forPattern("hh:mm a").withLocale(Locale.ENGLISH);
      DateTime dateTime1 = dtf.parseDateTime(string1.toString());
      DateTime dateTime2 = dtf.parseDateTime(string2.toString());
  
      final String oldf = ("hh:mm a");
      final String newf= ("hh.mm 0");
      final String newf2= ("hh.mm a");
      final String elapsedformat = ("hh.mm");
  
      SimpleDateFormat format2 = new SimpleDateFormat(oldf);
      SimpleDateFormat format2E = new SimpleDateFormat(newf); 
  
      Period timePeriod = new Period(dateTime1, dateTime2);
  
      PeriodFormatter formatter = new PeriodFormatterBuilder()
  
       .appendHours().appendSuffix(".")
       .appendMinutes().appendSuffix("")
       .toFormatter();
  
      String elapsed = formatter.print(timePeriod);
  
      table_4.setValueAt(elapsed,0,3);
  
      DecimalFormat df = new DecimalFormat("00.00");
      System.out.println(dateTime1);
      table_4.setValueAt("", 0, 4);
      table_4.setValueAt("", 0, 5);
  </code></pre>
  
  <p>Sample Data: </p>
  
  <pre><code>    dateTime1: 08:00 AM
      dateTime2: 05:00 PM
  </code></pre>
  
  <p>the period will be 9 hours. but i want it to be 8 hrs only because i want to subtract the lunch break in my program.</p>
  
  <p>i tried it with this stupid code:</p>
  
  <pre><code>dateTime1.minus(-1) 
  </code></pre>
  
  <p>I also tried parsing <code>string1</code> to double so I can subtract it by one.</p>
  
  <pre><code>double strindtoD = Integer.parseInt(string1);
  </code></pre>
  
  <p>I also tried making another <code>DateTime</code> and use period to get the difference of the two time</p>
  
  <pre><code>String stringOneHour = ("01:00 AM");
  DateTime dateTime3 = dtf.parseDateTime(stringOneHour.toString());
  Period timePeriod = new Period(dateTime3, dateTime1);
  </code></pre>