title: Manually Set System Clock Screws Up UTC in Android and IOS
body: <p>A continuation of a previous post:
  <a href="https://stackoverflow.com/questions/34909745/utc-string-to-date-and-utc-time-calculations">UTC String to Date and UTC Time Calculations</a></p>
  
  <p>Getting UTC time on a Phone where the time is manually set +5 hours, also changes UTC by 5 hours in both Android and IOS. Why is this?</p>
  
  <p><strong>IOS:</strong></p>
  
  <pre><code>+ (NSString*) getNowUtc
  {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
    // or
    //[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
  
    [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
  
    NSDate *now = [[NSDate alloc] init];
    return [formatter stringFromDate:now];
  }
  
  + (NSDate*) stringToDateInUtc:(NSString*)str
  {
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
    // or
    //[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
    return [formatter dateFromString:str];
  }
  
  + (NSDate*) getNowUtcAsDate
  {
    return [TimeHelper stringToDateInUtc:[TimeHelper getNowUtc]];
  }
  </code></pre>
  
  <p><strong>Android:</strong></p>
  
  <pre><code>public static Date getNowUtc()
  {
      return stringToDate(dateToString(new Date()));
  }
  
  public static Date stringToDate(String dateString)
  {
  
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
      TimeZone timeZone = TimeZone.getTimeZone("GMT");
      format.setTimeZone(timeZone);
  
      try
      {
          Date date = format.parse(dateString);
          return date;
      }
      catch (ParseException ex) {}
  
      return null;
  
  }
  </code></pre>
  
  <p>I have looked at <strong>DST</strong> for both Android and IOS. On IOS these values are 0 and on Android they return 3600 if a Date with UTC TimeZone is converted to a Local TimeZone (+1 GMT here... so) but adding +5 hours to the system clock does break all calculations based on time. And on Android, <strong>getRawOffset()</strong> and <strong>getOffset()</strong> - methods...</p>
  
  <p>How can I obtain a 100% certain UTC NSDate/Date when the system clock has been manually changed or automatically otherwise? UTC is not supposed to change. Is the only option to check for a date against some timeserver - which isn't failsafe.</p>