nstimezone

iOS create date in the future ignoring daylight savings

梦想与她 提交于 2019-12-05 01:42:41
I'm trying to work with dates and create dates in the future, but daylight savings keeps getting in the way and messing up my times. Here is my code to move to midnight of the first day of the next month for a date: + (NSDate *)firstDayOfNextMonthForDate:(NSDate*)date { NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; calendar.timeZone = [NSTimeZone systemTimeZone]; calendar.locale = [NSLocale currentLocale]; NSDate *currentDate = [NSDate dateByAddingMonths:1 toDate:date]; NSDateComponents *components = [calendar components:NSYearCalendarUnit |

How to manage NSDate for different timezones

柔情痞子 提交于 2019-12-04 16:50:17
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/yyyy"; [gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; NSDateComponents

Convert GMT time to local time

安稳与你 提交于 2019-12-03 09:48:54
I got current GMT time - 2013-05-15 08:55 AM my current local time is - 2013-05-15 02:06 PM and time zone is - Asia/Kolkata I tried to convert the above GMT to my local time with this code NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"Asia/Kolkata"]; [dateFormatter setTimeZone:sourceTimeZone]; // timeStamp - is the above GMT time NSDate *dateFromString = [dateFormatter dateFromString:timeStamp]; NSLog(@"local time is %@",dateFromString); but this give me wron time as - 2013-05-14 19:04:00 +0000 instead of 2013-05-14 02:06 PM Why this happens? please help me to clear this

Convert NSDate to NSString with NSDateFormatter with TimeZone without GMT Time Modifier

风流意气都作罢 提交于 2019-12-03 04:46:31
I'm initializing my NSDateFormatter thusly: NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; [dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss z"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; NSDate *date = [NSDate date]; NSString *dateString = [dateFormatter stringFromDate:date]; dateString is now: Thu, 29 Jul 2010 14:58:42 GMT+00:00 I want to get rid of the "+00:00" I'm guessing from http://unicode.org/reports/tr35/tr35-6.html#Time

iOS - How to get raw offset for timezone?

天涯浪子 提交于 2019-12-03 04:30:35
How do I get the raw offset in milliseconds for Coordinated Universal Time in iOS programmatically? NSInteger millisecondsFromGMT = 1000 * [[NSTimeZone localTimeZone] secondsFromGMT]; In Swift 3 and Swift 4: let millisecondsFromGmt = 1000 * TimeZone.autoupdatingCurrent.secondsFromGMT() schmidt9 Please see answer to my question: https://stackoverflow.com/a/31988549/3004003 It seems to be more precise regarding expression raw offset , because "raw" actually should mean "without DST at all", like it is in Java ( getRawOffset() in java.util.TimeZone class) 来源: https://stackoverflow.com/questions

iOS NSDateFormatter needs NSLocale even it's UTC

若如初见. 提交于 2019-12-01 22:41:05
I have a doubt that I cannot understand why is the way it is and I appeal to the Gods of this site :) I have a date coming like this: "1982-01-01T00:00:00Z" As I'm displaying whatever the server sends (I know, customer requirement, not good practice...), I'm forcing the device to have that TimeZone with the following method, simplified without error checking, not optimized, and all that kind of things: + (NSString *) yearStringFromDate: (NSDate *) date { NSDateFormatter *formatter = [NSDateFormatter new]; [formatter setDateFormat:@"YYYY"]; [formatter setTimeZone:[self timezoneForSIHF]]; return

GMT to Local Time Conversion with Daylight Saving Time change

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 09:51:57
问题 From server I'm receiving GMT time structure(user defined structure), using that I want to convert it into local time, I have done it by filling the NSDatecomponent with the structure received, and then I have used date formattter to get date from it, everything works fine except one case. If the GMT time is after Nov 3 (Daylight Saving Time change in US) formatter is producing 1 hour time difference. for eg: If the intended time is for Nov-3 ,4 PM, after conversion from GMT to local its

NSCalendar dateFromComponents: GMT timezone instead of systemTimeZone

倾然丶 夕夏残阳落幕 提交于 2019-12-01 05:26:40
This code NSCalendar *calendar =[NSCalendar currentCalendar]; [gregorian setTimeZone:tz]; NSLog(@"%@", [gregorian timeZone]); NSDateComponents *comp = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit) fromDate:[NSDate date]]; [comp setDay:info.day]; [comp setMonth:info.month]; [comp setYear:info.year]; [comp setHour:info.hour]; [comp setMinute:info.minute]; [comp setSecond:info.second]; [comp setTimeZone:tz]; NSLog(@"%@", [comp timeZone]); NSLog(@"%@", [gregorian dateFromComponents:comp]); shows the following in console: Europe/Moscow (MSKS) offset 14400 (Daylight) Europe/Moscow

Translate Time Zone Names to Time ID:s

自作多情 提交于 2019-11-30 21:53:51
I found out that iOS framework doesn’t understand proper time zone names, like "Eastern Standard Time”. If you type: NSLog(@"EST: %@", [NSTimeZone timeZoneWithName:@"Eastern Standard Time"]); … you get: EST: (null) Instead, you have to use time ID:s (a narrower area), like "America/New_York" for example: NSLog(@"EST: %@", [NSTimeZone timeZoneWithName:@"America/New_York"]); ... then the console kindly responds: EST: America/New_York (GMT-4) offset -14400 (Daylight) Is there any way to translate time zone names to time ID:s? Because the web-API I’m using is giving me time zone names, not the