title: Retrieving a UTC datetime from a data source -- putting it into a Joda DateTime object and persisting it to MongoDB. What is the best way?
body: <p>I am pulling data from an external source into my program and it has an ISO8601 Date attached to it but one of our requirements is that the hour/minutes/seconds get set to zero. This happens before I receive the date. So I get this from the data.</p>
  
  <pre><code>2013-05-17T00:00:00.000Z
  </code></pre>
  
  <p>for instance. I am then putting that value into a Joda DateTime object called "businessDay". I do some processing based off of this value but then I need to persist it to MongoDB.</p>
  
  <p>Since a Joda DateTime object is not serializable I need to put the DateTime object into a Date object and persist it to Mongo (and reverse that when it comes out).</p>
  
  <p>When I use Joda in this way
  <code>businessDay.toDate()</code> -- I receive a Java Date object but it is </p>
  
  <pre><code>Sun May 19 20:00:00 EDT 2013
  </code></pre>
  
  <p>and businessDay printed out normally is</p>
  
  <pre><code>2013-05-20T00:00:00.000Z
  </code></pre>
  
  <p>It converts it to my local time zone, which is then making it the previous day.
  What I want is to convert the DateTime object into a Date object that retains the values. </p>
  
  <p>I've been trying a bunch of things with DateTimeFormatter but I can't get it to work at all. I've also been deleting all of my efforts otherwise I would paste them here but I've been doing this all day to try to figure this out.</p>
  
  <p>Thank you for any assistance.</p>
  
  <p>EDIT:</p>
  
  <p>Showing method that converts a String Date into a Joda DateTime object. </p>
  
  <pre><code> private DateTime asDateTime(String value) {
          // Was experiencing an issue converting DateTime to date, it would convert to localtime zone
          // giving me the wrong date. I am splitting the value into its year/month/day values and using a dateFormatter
          // to give me an appropriate format for the date. Timezone is based on UTC.
          String[] splitValue = value.split("-");
          String[] splitDay = splitValue[2].split("T");
          int year = Integer.parseInt(splitValue[0]);
          int month = Integer.parseInt(splitValue[1]);
          int day = Integer.parseInt(splitDay[0]);
          DateTime date = new DateTime(DateTimeZone.UTC).withDate(year, month, day).withTime(0, 0, 0, 0);
          return date;
      }
  </code></pre>