nstimezone

getting hour component from an NSDate

自古美人都是妖i 提交于 2019-12-12 05:33:23
问题 I'm trying to get the hour component from an NSDate . Here is what I do: NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; [calendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT+1"]]; NSDateComponents *startComponents = [calendar components:DATE_COMPONENTS fromDate:_start]; startComponents.timeZone = [NSTimeZone timeZoneWithName:@"GMT+1"]; int hours = [startComponents hour]; Now before yesterday the hours value always was one hour ahead. But since

Save date in 'GMT' timezone in sqlite database

ぃ、小莉子 提交于 2019-12-12 01:26:28
问题 I am using Core-Data to store date-time object. Eg. 2015-07-28T07:16:52+0000 this is date in ISO format in GMT timezone. But when I save this date in database NSString* dateString=@"2015-07-28T07:16:52+0000"; NSDateFormatter* dateTimeformatter=[[NSDateFormatter alloc] init]; [dateTimeformatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; [dateTimeformatter dateFromString:dateString]; the resulting date which I see in database is 2015-07-28 12:46:52 which is in IST according to my device's

NSDate behaviour when saving to plist

柔情痞子 提交于 2019-12-10 14:26:15
问题 I am creating a date from [NSdate date] and saving it to plist, Here is how I am creating a date - (void)applicationWillResignActive:(UIApplication *)application { NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; // [gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSMinuteCalendarUnit)fromDate:[NSDate date]

How to calculate the time difference between two locations

泄露秘密 提交于 2019-12-10 10:13:52
问题 I am having a problem with calculating time difference between two timeZones. If I am at location A I know the latitude and longitude and the current time. I go to location B I know the latitude and longitude and the current time. How to calculate the time difference between the two current points .. (in UTC) 回答1: Firstly get a database or library that converts lat/long to get the country and state/province. Then use the NSTimeZone class to retrieve the timezone for a particular country. You

How to manage NSDate for different timezones

孤街醉人 提交于 2019-12-09 22:17:11
问题 I have created a calendar in my app, using the date object this way: NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSMinuteCalendarUnit)fromDate:[NSDate date]]; NSInteger day = [weekdayComponents day]; NSInteger month = [weekdayComponents month]; NSInteger year = [weekdayComponents year]; m_dateFormatter.dateFormat = @"dd/MM

Get number of days between two NSDate dates in a particular timezone

喜你入骨 提交于 2019-12-09 11:37:30
问题 I found the codes to calculate days difference between two dates here. I write a method : -(NSInteger)daysWithinEraFromDate:(NSDate *) startDate toDate:(NSDate *) endDate { NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSInteger startDay=[gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit: NSEraCalendarUnit forDate:startDate]; NSInteger endDay=[gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit: NSEraCalendarUnit forDate:endDate]; return endDay

objective-c: Conversion between TimeZones

ⅰ亾dé卋堺 提交于 2019-12-06 14:51:52
问题 I'm having problems converting a time string to a different timeZone. This is a string example as the one I retrieve from a server: @"5/14/2013 4:19am" I know the timeZone is America/New_York and I want to convert it to my local timeZone: Europe/Rome. Here is the code I wrote to test it: -(void) convertTimeZone { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.timeZone=[NSTimeZone timeZoneWithAbbreviation:@"GMT"]; dateFormatter.dateFormat=@"MM/dd/yyyy HH:mma";

How to get the time zone name for a CLLocation

て烟熏妆下的殇ゞ 提交于 2019-12-06 10:41:50
I have an application that uses a CLGeocoder to forwardGeocode a placemark from an address string. The CLPlacemark response contains a CLLocation which gives me GPS coordinates. The only way to create an NSTimeZone seems to be by using the correct Time Zone Name. It is important to point out that I am not using the current location of the device, so [NSTimeZone localTimeZone] will not work for me. Is there a way to get the timezone name for the CLLocation so that I can create an NSTimeZone correctly? NOTE: I have been using timeZoneForSecondsFromGMT but that never contains correct DST data, so

iPhone NSTimeZone: localTimeZone confusion

情到浓时终转凉″ 提交于 2019-12-06 09:33:47
问题 From what I understand, calling NSLog(@"Local Time Zone %@",[[NSTimeZone localTimeZone] name]); gives you the local time zone of the device. What it's giving me is "US/Central" , and I can't find that anywhere in the list of abbreviations in [NSTimeZone abbreviationDictionary] , or the list of time zone names in [NSTimeZone knownTimeZoneNames] . Where is this one coming from? I need to pass the current device time zone to a Rails app, and it understands things like "Australia/Sydney" or

How to calculate the time difference between two locations

人走茶凉 提交于 2019-12-05 19:57:42
I am having a problem with calculating time difference between two timeZones. If I am at location A I know the latitude and longitude and the current time. I go to location B I know the latitude and longitude and the current time. How to calculate the time difference between the two current points .. (in UTC) Firstly get a database or library that converts lat/long to get the country and state/province. Then use the NSTimeZone class to retrieve the timezone for a particular country. You can purchase such databases from many sites, ie: http://www.ip2location.com/ To do the actual conversion you