title: Java Simple Date Format Parse - returning wrong date Time Zone issue?
body: <p>Sorry, I think I've spent too long on this and have got confused.</p>
  
  <p>I've got the following code:</p>
  
  <pre><code>    System.out.println("Time Now: " + new Date());    
  
      Calendar beginningOfDay = new GregorianCalendar();
  
      beginningOfDay.set(Calendar.HOUR_OF_DAY, 0);
      beginningOfDay.set(Calendar.MINUTE, 0);
      beginningOfDay.set(Calendar.SECOND, 0);
      beginningOfDay.set(Calendar.MILLISECOND, 0);
  
      SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");  
  
      Date specifiedTime = null;
      try{
          specifiedTime = sdf.parse("20:55");     // this time is extracted from interface     
      } catch(ParseException pe){}        // complete this later
  
      System.out.println("specified time is: " + specifiedTime);
  
       Calendar runResults = new GregorianCalendar(TimeZone.getDefault());
       if (beginningOfDay.getTimeInMillis() + specifiedTime.getTime() &gt; System.currentTimeMillis())
       {  System.out.println("specified time has not occured yet");
          runResults.setTimeInMillis(beginningOfDay.getTimeInMillis() + specifiedTime.getTime());
          System.out.println("Time to run tests is: " + runResults.getTime()); 
       }
       else
       {  System.out.println("need to run tests tomorrow");
          beginningOfDay.add(Calendar.DATE, 1);       // add a day
          runResults.setTimeInMillis(beginningOfDay.getTimeInMillis() + specifiedTime.getTime());
          System.out.println("Time to run tests is: " + runResults.getTime());  
       }
  </code></pre>
  
  <p>Which gives the following output:</p>
  
  <pre><code>Time Now: Thu Aug 25 20:17:52 BST 2011
  specified time is: Thu Jan 01 20:55:00 GMT 1970
  need to run tests tomorrow
  Time to run tests is: Fri Aug 26 19:55:00 BST 2011
  </code></pre>
  
  <p>So why is the specifiedTime parse coming back with 19:55 BST?</p>
  
  <p>I've tried to set the sdf (simpledateformatter) timezone to be the same as the calendar but it doesn't seem to work.</p>
  
  <p>Ideally what I want is to get whatever time is parsed (e.g. "20.55") to be converted to a time in the local timezone, and if that time has not happened yet then a Timer is set to go off at that time, otherwise it should wait until the next day. This is the code with which I am trying to calculate the time the Timer initiates the TimerTask. If anyone can suggest a better solution I would be very grateful. The Timer should initiate the TimerTask when the local time is the one in the specifiedTime.</p>
  
  <p>Thanks again for any help.</p>
  
  <p>EDIT:</p>
  
  <p>used this to get it to work. Not very neat though</p>
  
  <pre><code>    Calendar timeNow = new GregorianCalendar();
  
      String timeNowString = timeNow.getTime().toString();
      String timeNowFirstBit = timeNowString.substring(0, 10); // e.g. "Sat Aug 27"
      String timeNowLastBit =  timeNowString.substring(24); // e.g. "2011"
  
      String userSpecifiedTime = "14:32";    
      SimpleDateFormat specTimeFormat = new SimpleDateFormat("EEE MMM dd HH:mm yyyy");
      String allNewSpecifiedTime = timeNowFirstBit + " " + userSpecifiedTime + " " +                                                                 timeNowLastBit;
  
      Date specifiedTime = null;
      try{
      specifiedTime = specTimeFormat.parse(allNewSpecifiedTime);
      }   catch (ParseException pe){}
  
       Calendar runResults = new GregorianCalendar();
       runResults.setTimeInMillis(specifiedTime.getTime());
       if (specifiedTime.getTime() &gt; System.currentTimeMillis())
       {  System.out.println("specified time has not occured yet");          
       }
       else
       {  System.out.println("need to run tests tomorrow");
          runResults.add(Calendar.DATE, 1);       // add a day          
       }
          System.out.println("Time to run tests is: " + runResults.getTime()); 
  </code></pre>