Tag: nstimezone

在“GMT”时区在sqlite数据库中保存date

我正在使用Core-Data来存储date时间对象。 例如。 2015-07-28T07:16:52+0000这是GMT时区ISO格式的date。 但是当我在数据库中保存这个date 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]; 我在数据库中看到的结果date是2015-07-28 12:46:52 根据我的设备的时区在IST 我试图在dateFormatter中设置时区,但同样的响应 NSString* dateString=@"2015-07-28T07:16:52+0000"; NSDateFormatter* dateTimeformatter=[[NSDateFormatter alloc] init]; [dateTimeformatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; [dateTimeformatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; [dateTimeformatter dateFromString:dateString]; 即使将[NSDate date]直接保存在数据库中,它也会根据设备的时区保存转换的date。 为什么Core-data不考虑NSDateFormatter的时区? 任何人都可以告诉我如何可以将数据库中的dateGMT保存在数据库中,而不pipe我的设备的时区?

date比较或时区未正确设置

我试图做一个简单的比较date的意图移动到另一个数组索引的基础上的一天。 尽pipe比我使用的代码更高效,但以下( 无法parsingdate )不会保留时区偏移: let noaaDate = "2014-08-22T15:00:00-04:00" let format="yyyy-MM-dd'T'HH:mm:ssZ" var dateFmt = NSDateFormatter() dateFmt.dateFormat = format let newreadableDate = dateFmt.dateFromString(noaaDate) println(newreadableDate) 输出: Optional(2014-08-22 19:00:00 +0000) 当我添加以下内容: dateFmt.timeZone = NSTimeZone.localTimeZone() // I've even tried defaultTimeZone 输出是一样的。 哪里这似乎成为一个问题是以后我做了以下事情: // FYI: parseNOAADateTime is that code above var earliestTimeNS = parseNOAADateTime(earliestTime!) let calendar = NSCalendar.currentCalendar() let components = […]

NSDate保存为plist时的行为

我从[NSdatedate]创builddate并将其保存为plist,以下是我如何创builddate – (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]]; NSInteger day = [weekdayComponents day]; NSInteger month = [weekdayComponents month]; NSInteger year = [weekdayComponents year]; NSDateComponents *timeZoneComps=[[NSDateComponents alloc] init]; [timeZoneComps setDay:day]; [timeZoneComps setMonth:month]; [timeZoneComps setYear:year]; [timeZoneComps setHour:00]; [timeZoneComps […]

iOS在未来创builddate忽略夏令时

我正在努力与date和date创builddate,但夏令时不断阻碍和混乱了我的时代。 这里是我的代码移动到下个月的第一天的午夜为一个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 | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:currentDate]; [components setDay:1]; [components setHour:0]; [components setMinute:0]; [components setSecond:0]; return [calendar dateFromComponents:components]; } + (NSDate *) dateByAddingMonths: (NSInteger) monthsToAdd toDate:(NSDate*)date […]

如何pipe理不同时区的NSDate

我已经在我的应用程序中创build了一个日历,用这种方式使用date对象: 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 *timeZoneComps=[[NSDateComponents alloc] init]; [timeZoneComps setDay:day]; [timeZoneComps setMonth:month]; [timeZoneComps setYear:year]; [timeZoneComps setHour:00]; [timeZoneComps setMinute:00]; [timeZoneComps […]

将GMT时间转换为当地时间

我现在得到GMT时间 – 2013-05-15 08:55 AM 我目前的当地时间是 – 2013-05-15 02:06 PM和时区是 – 亚洲/加尔各答 我试图用上面的代码把上面的GMT转换成我的本地时间 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); 但是这给我这个时间 – 2013-05-14 19:04:00 +0000而不是2013-05-14 02:06 PM 为什么会发生? 请帮我明确这一点。提前感谢

格林尼治标准时间到本地时间转换夏时制改变

从服务器我收到格林尼治标准时间结构(用户定义的结构),使用,我想将其转换为本地时间,我已经完成填充NSDatecomponent收到的结构,然后我已经使用dateformatter获取date它,除了一个案件,一切正常。 如果GMT时间在11月3日(美国夏令时改变)之后格式化器产生1小时时差。 例如:如果预计时间是11月3日下午4点,格林尼治标准时间从格林威治标准时间转换到当地时间为11月3日下午3点。 任何想法如何避免它。 编辑: // Selected Dates NSDateComponents *sel_date = [[NSDateComponents alloc]init]; sel_date.second = sch_detail.sel_dates.seconds; sel_date.minute = sch_detail.sel_dates.mins; sel_date.hour = sch_detail.sel_dates.hours; sel_date.day = sch_detail.sel_dates.date; sel_date.month = sch_detail.sel_dates.month; sel_date.year = sch_detail.sel_dates.year; sel_date.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; // Get the Date format. NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; [gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; // Start_date formatter. NSDateFormatter *dateFormatter = […]

如何将服务器响应date转换为本地时区?

在API调用响应中,我得到不同时区的date。 我想将其转换为用户的本地时区,用户可以从ios时区列表中select任何时区。 这都是本地的。 我们永远不会发送选定的用户时区到服务器。 同时使任何API调用可以说我正在select器中创build一个事件与选定的开始date。 我应该发送全球时区不与用户select的时区,因为它是本地的应用程序。 目前我正在改变select的defaultTimeZone,以便我得到适当的当前date等。并使用setTimeZone NSDateFormatter … [NSTimeZone timeZoneWithName … 这是一个更好的方法来改变应用程序的所有本地的defaultTimeZone? 在将NSdate发送到服务器时,我应该如何将NSdate转换回全局date?

如何使用NSTimeZone -timeZoneWithName:从Rails的ActiveSupport的城市名称?

如果我只有曼谷或东京这样的城市名称,我该如何在[NSTimeZone timeZoneWithName:@"Asia/Tokyo"]中提供一个时区参数,在那里它也有大陆和斜线在城市前面? 我已经尝试[NSTimeZone timeZoneWithName:@"Tokyo"] ,它不起作用。

NSDate独立于时区?

我有一个应用程序,显示某些渡轮旅行的时间表。 如果我旅行到不同的时区 – 比如说4个小时,上午10点的渡轮旅程现在显示为上午6点? 我知道这与date如何根据他们的时区来处理有关,但我无法弄清楚如何改变这种行为。 目前,我是如何获取date并将其显示在UILabel上的: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"HH:mm"]; [self.departureTime setText:[dateFormatter stringFromDate:[self.route objectForKey:@"departureTime"]]]; [self.arrivalTime setText:[dateFormatter stringFromDate:[self.route objectForKey:@"arrivalTime"]]]; [dateFormatter release]; 在此先感谢您的帮助。