nstimezone

Convert GMT time to local time

◇◆丶佛笑我妖孽 提交于 2019-12-21 02:48:18
问题 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 -

iOS - How to get raw offset for timezone?

怎甘沉沦 提交于 2019-12-20 16:35:14
问题 How do I get the raw offset in milliseconds for Coordinated Universal Time in iOS programmatically? 回答1: NSInteger millisecondsFromGMT = 1000 * [[NSTimeZone localTimeZone] secondsFromGMT]; In Swift 3 and Swift 4: let millisecondsFromGmt = 1000 * TimeZone.autoupdatingCurrent.secondsFromGMT() 回答2: 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",

Where can I find a list of timezones? [closed]

*爱你&永不变心* 提交于 2019-12-20 08:34:17
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . I use timeZoneWithName, but I don't know names of timezones. Where can I find a list of timezones? [NSTimeZone timeZoneWithName:@"US/Eastern"]; 回答1: I found solution. NSLog(@"%@", [NSTimeZone knownTimeZoneNames]); 来源: https://stackoverflow.com/questions/9761847/where-can-i-find-a-list-of-timezones

NSCalendar dateFromComponents: GMT timezone instead of systemTimeZone

纵然是瞬间 提交于 2019-12-19 07:38:09
问题 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

How to use NSTimeZone -timeZoneWithName: with a city name from Rails ActiveSupport?

依然范特西╮ 提交于 2019-12-18 14:14:53
问题 If I only have the city name like Bangkok or Tokyo , how can I supply a timezone parameter in [NSTimeZone timeZoneWithName:@"Asia/Tokyo"] where it also has continent and slash in front of city? I already tried [NSTimeZone timeZoneWithName:@"Tokyo"] , it doesn't work. 回答1: Thanks for the answers guys, but it looks like those city names are just a format that Rails "ActiveSupport::TimeZone" uses. So I just have to map it back. The mapping is here -> http://api.rubyonrails.org/classes

GMT timezone conversion in objective c

安稳与你 提交于 2019-12-17 10:33:31
问题 I am trying to convert nsstring to nsdate and then to the systemtimezone. Is my code right? Any help appreciated. NSString *str=@"2012-01-15 06:27:42"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *dateFromString = [dateFormatter dateFromString:str]; NSDate* sourceDate = dateFromString; NSTimeZone* sourceTimeZone = [NSTimeZone

need to get central time in objective-c

亡梦爱人 提交于 2019-12-14 00:00:21
问题 I have app where i need to get the current time (CST). I'm trying to use the following code but the NDate is the same as GMT: NSDate* date = [NSDate date]; NSLog(@"Time is %@", [date description]); [NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CST"]]; NSDate* nDate = [NSDate date]; NSLog(@"Central time is%@", [nDate description]) 回答1: Beside the fact that the time has not timezone itself, but you have to add a calendar to set it in relation to a time zone as I

Objective C - How to get raw offset (without DST) using NSTimeZone

旧时模样 提交于 2019-12-13 07:51:16
问题 I'd like to get raw offset from GMT. I know the answer could be like that: NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"Europe/Berlin"]; NSInteger *offset = [zone secondsFromGMT]; (like here: iOS - How to get raw offset for timezone?) But the problem is, it doesn't give me raw offset (for Berlin +1), but only offset with DST (+2), that is, for the current date. 回答1: NSTimeZone has a property daylightSavingTimeOffset which returns the difference to the raw offset NSTimeZone *zone =