title: Timezone issue with Joda-time when converting a LocalTime to a DateTime using .toDateTime()
body: <p>I am writing some code to do periodic scheduling based based on time of day.  I am representing the regular schedule time of day as a Joda <code>LocalTime</code> object.  I then create event instances by converting the <code>LocalTime</code> to a <code>DateTime</code>.  When initially writing the code (and only scheduling events for "today") I used the <code>toDateTimeToday()</code> method on <code>LocalTime</code> and it worked as expected.  However when I switched to using the <code>toDateTime()</code> method to schedule events in the future I started seeing issues with mapping between UTC and local local timezone.</p>
  
  <p>The following code demonstrates the problem I am seeing.</p>
  
  <pre><code>DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
  
  LocalTime lt = new LocalTime(12,0);
  System.out.println(" lt="+lt);
  
  DateTime dtt = lt.toDateTimeToday();
  System.out.println("dtt="+df.format(dtt.toDate()));
  
  DateTime bdt = new DateTime();
  System.out.println("bdt="+df.format(bdt.toDate()));
  
  DateTime dt = lt.toDateTime(bdt.toInstant());
  System.out.println(" dt="+df.format(dt.toDate()));
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre><code> lt=12:00:00.000
  dtt=2014-07-08T12:00:00-0400
  bdt=2014-07-08T18:01:30-0400
   dt=2014-07-08T08:00:00-0400
  </code></pre>
  
  <p>As you can see, the <code>dtt</code> and <code>dt</code> should be the same time, but they are different by the local timezone offset.</p>
  
  <h2>UPDATE</h2>
  
  <p>Based on Matt Johnson's answer, I made a simple change in my code, replacing:</p>
  
  <pre><code>DateTime dt = lt.toDateTime(bdt.toInstant());
  </code></pre>
  
  <p>with</p>
  
  <pre><code>DateTime dt = new LocalDate(bdt).toDateTime(lt); 
  </code></pre>
  
  <p>My code updated with the change (plus switching to Joda formatting) is as follows:</p>
  
  <pre><code>DateTimeZone.setDefault(DateTimeZone.forTimeZone(TimeZone.getDefault()));
  
  DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
  DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ");
  
  LocalTime lt = new LocalTime(12,0);
  System.out.println(" lt="+lt);
  
  DateTime dtt = lt.toDateTimeToday();
  System.out.println("dtt="+dtt.toString(fmt));
  
  DateTime bdt = new DateTime();
  System.out.println("bdt="+bdt.toString(fmt));
  
  DateTime dt = new LocalDate(bdt).toDateTime(lt);
  System.out.println(" dt="+dt.toString(fmt));
  </code></pre>
  
  <p>Here's the new (correct!!) output.</p>
  
  <pre><code> lt=12:00:00.000
  dtt=2014-07-09T12:00:00-0400
  bdt=2014-07-09T00:15:35-0400
   dt=2014-07-09T12:00:00-0400
  </code></pre>
  
  <p>Thanks Matt!</p>