Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>[NSDate date] is taking default timezone as GMT. so, I am unable to set my local timezone to date. </p> <p>While knowing the difference between GMT OFFset to local , I am able to get the difference between two dates sucessfully.</p> <pre><code>NSDate* sourceDate = [NSDate date]; NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone]; NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate]; NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate]; NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset; NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate]; NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; [outputFormatter setAMSymbol:@"AM"]; [outputFormatter setPMSymbol:@"PM"]; [outputFormatter setLocale:[NSLocale currentLocale]]; [outputFormatter setDateFormat:@"MM/dd/yyyy hh:mm a"]; NSDate *gameDate = [outputFormatter dateFromString:gameTime]; NSDate* gameDestinationDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:gameDate]; // NSLog(@"gameDate=%@",gameDate); NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit; NSDateComponents *components = [gregorian components:unitFlags fromDate:destinationDate toDate:gameDestinationDate options:0]; NSInteger days = [components day]; NSInteger hours = [components hour]; NSInteger seconds = [components second]; NSInteger minutes = [components minute]; return ([NSString stringWithFormat:@"%01ddays:%02dhrs:%02dmins:%02dsec",abs(days),abs(hours), abs(minutes), abs(seconds)]); </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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