Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //method to get the current time (as per the location)
- -(NSDate *)getCurrentTime{
- NSDate *currentDate = nil;
- NSDate *date = [NSDate date];
- NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
- NSInteger currentGMTOffset = [currentTimeZone secondsFromGMTForDate:date];
- NSInteger gmtOffset = [currentTimeZone secondsFromGMTForDate:date];
- NSTimeInterval gmtInterval = currentGMTOffset - gmtOffset;
- NSDate *destinationDate = [[NSDate alloc] initWithTimeInterval:gmtInterval sinceDate:date] ;
- NSDateFormatter *dateFormatters = [[NSDateFormatter alloc] init];
- [dateFormatters setDateFormat:@"dd-MMM-yyyy HH:mm:ss"];
- [dateFormatters setDateStyle:NSDateFormatterShortStyle];
- [dateFormatters setTimeStyle:NSDateFormatterMediumStyle];
- [dateFormatters setDoesRelativeDateFormatting:YES];
- [dateFormatters setTimeZone:[NSTimeZone systemTimeZone]];
- NSString *dateStr = [dateFormatters stringFromDate: destinationDate];
- NSLog(@"%@",dateStr);
- currentDate = [dateFormatters dateFromString:dateStr];
- NSLog(@"%@",currentDate);
- return currentDate;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement