Note that there are some explanatory texts on larger screens.

plurals
  1. PONSDateFormatter not working to set setTimeZone
    primarykey
    data
    text
    <p>I am trying to know the difference between two dates (Including days,hours,minutes and seconds). For that I am using below code, but It's not working. </p> <pre><code>+ (void)UpdateTableViewCellWithNSTimer:(NSString *)gameTime :(UIView *)inputView{ NSDate *now = [NSDate date]; NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; [outputFormatter setLocale:[NSLocale systemLocale]]; [outputFormatter setAMSymbol:@"AM"]; [outputFormatter setPMSymbol:@"PM"]; [outputFormatter setTimeZone:[NSTimeZone localTimeZone]]; [outputFormatter setDateFormat:@"mm/dd/yyyy hh:mm a"]; NSDate *gameDate = [outputFormatter dateFromString:gameTime]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit; NSDateComponents *components = [gregorian components:unitFlags fromDate:gameDate toDate:now options:0]; NSInteger days = [components day]; NSInteger hours = [components hour]; NSInteger seconds = [components second]; NSInteger minutes = [components minute]; UITableView *dynamicTable = (UITableView *)[inputView viewWithTag:55]; NSIndexPath *cellIndexPath = [NSIndexPath indexPathForRow:4 inSection:0]; UITableViewCell *currentCell = [dynamicTable cellForRowAtIndexPath:cellIndexPath]; NSString *challengeStartsIn=[NSString stringWithFormat:@"%01ddays:%02dhrs:%02dmins:%02dsec",abs(days),abs(hours), abs(minutes), abs(seconds)]; NSString *Mystring =[NSString stringWithFormat:@"%@ %@", @"ChallengeStartsIn", challengeStartsIn]; currentCell.textLabel.text = Mystring; } **Game and now dates on logs are:** 2013-05-18 11:36:42.609 FPPresent[2213:5203] gametime value=05/19/2013 5:30 AM 2013-05-18 11:36:42.610 FPPresent[2213:5203] now=2013-05-18 06:06:42 +0000 </code></pre> <p><strong>After using outputformatter</strong>:</p> <pre><code> gametime value =2013-01-19 00:00:00 +0000(It should be 2013-01-19 05:30:00 +0000 ) now=2013-05-18 06:10:07 +0000(should be : 2013-05-18 11:40:07 +0000) </code></pre> <p>The game date and now date should in localTimeZone. But, even I try to set </p> <pre><code>[outputFormatter setTimeZone:[NSTimeZone localTimeZone]]; </code></pre> <p>My data format is showing (Exactly 5.30 hours different, our local time zone is GMT+5.30)</p> <p>Please let me know where I am going wrong</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload