nstimezone

Translate Time Zone Names to Time ID:s

半腔热情 提交于 2019-11-30 17:29:44
问题 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

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

拜拜、爱过 提交于 2019-11-30 11:09:24
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. 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/ActiveSupport/TimeZone.html It maps the timezone from Rails "ActiveSupport::TimeZone" format to another format that

NSDate independent of timezone?

牧云@^-^@ 提交于 2019-11-30 08:31:56
问题 I have an app that displays a timetable of certain ferry trips. If I travel to a different timezone - say 4 hours behind, a 10am ferry trip now shows up as 6am? I know this has got to do with how dates are treated based on their timezones, but I can't work out how to change that behaviour. At the moment here's how I am getting the date and displaying it on a UILabel: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"HH:mm"]; [self.departureTime

NSDate independent of timezone?

跟風遠走 提交于 2019-11-29 06:52:56
I have an app that displays a timetable of certain ferry trips. If I travel to a different timezone - say 4 hours behind, a 10am ferry trip now shows up as 6am? I know this has got to do with how dates are treated based on their timezones, but I can't work out how to change that behaviour. At the moment here's how I am getting the date and displaying it on a UILabel: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"HH:mm"]; [self.departureTime setText:[dateFormatter stringFromDate:[self.route objectForKey:@"departureTime"]]]; [self.arrivalTime

How to identify timezone from longitude and latitude in iOS

社会主义新天地 提交于 2019-11-28 00:56:57
How can I find out which NSTimeZone a given longitude and latitude fall in? Roohul I have tried APTimeZones library. In my case I needed Timezone as well as country name from the lat long of a particular city. I went through the library to know how it works. It actually has a file in JSON format which has all the timezones along with their corresponding lat longs. it takes the lat long as input and loops through this JSON file comparing the distances of all the timezone's lat long from the input lat long. It returns the time zone which has shortest distance from the input lat long. But the

ios时间那点事--NSCalendar NSDateComponents

混江龙づ霸主 提交于 2019-11-27 12:05:51
#iOS时间那点事 ##NSCalendar + NSDateComponents 历法能使人类确定每一日再无限的时间中的确切位置并记录历史。 日历,历法,一般历法都是遵循固定的规则的,具有周期性。日历都是已知的或可预测的。 任何一种具体的历法,首先必须明确规定起始点,即开始计算的年代,这叫“纪元”;以及规定一年的开端,这叫“岁首”。此外,还要规定每年所含的日数,如何划分月份,每月有多少天等等。 NSCalendar对世界上现存的常用的历法进行了封装,既提供了不同历法的时间信息,又支持日历的计算。 NSDateFomatter 表示的时间默认以公历(即阳历)为参考,可以通过设置calendar属性变量获得特定历法下的时间表示。 NSDate 是独立与任何历法的,它只是时间相对于某个时间点的时间差; NSDate 是进行日历计算的基础。 NSDateComponents将时间表示成适合人类阅读和使用的方式,通过NSDateComponents可以快速而简单地获取某个时间点对应的“年”,“月”,“日”,“时”,“分”,“秒”,“周”等信息。当然一旦涉及了年月日时分秒就要和某个历法绑定,因此NSDateComponents必须和NSCalendar一起使用,默认为公历。 NSDateComponents除了像上面说的表示一个时间点外,还可以表示时间段,例如:两周,三个月,20年,7天

iOS时间那点事--NSTimeZone

柔情痞子 提交于 2019-11-27 12:05:38
#iOS时间那点事 ##NSTimeZone **时区是一个地理名字,是为了克服各个地区或国家之间在使用时间上的混乱。 ###基本概念: GMT 0:00 格林威治标准时间; UTC +00:00 校准的全球时间; CCD +08:00 中国标准时间 [来自百度百科] 夏时制,英文"DaylightSavingTime"。夏季时将时区内的时间提前(一般为1小时),以节省资源,提高效率。使用夏时制期间,当前时区相对于GMT的时间偏移量会发生变化。在某些应用中可能需要考虑。 任何时区都以GMT为基准,即,任何NSTimeZone对象所代表的时区都是相对于GMT的,这里的相对性是NSTimeZone中最重要的属性,我们称之为当前时区相对于GMT的偏移量。一旦知道了一个偏移量,便可以确定一个时区。在iOS中,偏移量是以"秒"为单位的。 NSTimeZone是一个类簇,我们所使用的任何NSTimeZone对象都是NSTimeZone的私有子类。 iOS中的时间类NSDate中存储的时间,都是相对于GMT的,我们使用NSDate时,会根据App的时区设置返回与时区对应的数据。 iOS系统中的/usr/share/zoneinfo/目录中保存了所有的可根据 地理位置名称 或 时区别名 得到的时区信息。时区别名都是与具体的地理位置一一对应的。(已越狱的童鞋请看) iOS中的时区表示方法:GMT

GMT timezone conversion in objective c

倾然丶 夕夏残阳落幕 提交于 2019-11-27 11:51:37
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 timeZoneWithAbbreviation:@"GMT-07:00"]; NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone]; NSInteger

iPhone - Differences among time zone convenience methods

杀马特。学长 韩版系。学妹 提交于 2019-11-27 10:44:09
I see that NSTimeZone has these methods : defaultTimeZone localTimeZone systemTimeZone Can someone explain to me, in simple terms, what the differences are beetween those calls, and when one should be used instead of the other? I don't understand anything inside the Apple docs about this. Josh Caswell The language in the docs is a bit on the dry side, to be sure, and the similarity of the names is potentially confusing. I'll quote the NSTimeZone docs here and try to explain them: systemTimeZone The time zone currently used by the system. If the current time zone cannot be determined, returns

Detect if time format is in 12hr or 24hr format

隐身守侯 提交于 2019-11-27 01:02:04
问题 Is there any way to detect if the current device of the app uses 12h our 24h format, so that I can use one NSDateFormatter for 12h and one for 24h depending on the users language/loaction setting? Just Like the UIDatePicker detects and shows the AM/PM picker if it is 12h format. 回答1: I figured it out, its pretty easy. I just added this code to viewDidLoad : NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setLocale:[NSLocale currentLocale]]; [formatter setDateStyle