nsdate

Best way to synchronize iPhone time with the server

孤人 提交于 2019-12-10 13:13:21
问题 I have a client server model where server will send some data which has date parameters and iPhone will need to render it. Server and iPhone will resides in different timezones. So I need to synchronize times in both. Let say user has done some activity at "07/18/2011/04 /45/EDT" (server time). From the iPhone end I need to convert this date string into a NSDate object. What is the best way to achieve this. Thank you 回答1: Sorry for the late response, just looked for "NSDate Sync to Server" on

Why does [NSDate date] return id?

折月煮酒 提交于 2019-12-10 12:49:47
问题 Why doesn't it return NSDate* ? It's supposed to be a creation function right? All creation function return the class whose type is the class creating it. Now, I can't do NSDate.date.timeIntervalSince1970 :( I thought the compiler is smart enough to know that NSDate.date return NSDate even though the return type is id? 回答1: UPDATE Starting from iOS 7, Apple is using instancetype as return type for most of the Foundation framework APIs (and other frameworks too), so now for instance the +date

Get calendarweek of an NSDate according ISO 8601

♀尐吖头ヾ 提交于 2019-12-10 12:16:38
问题 is there a way to get calendarweek of an NSDate according ISO 8601. I think: Datecomponents *dateComponents = [cal components:(NSWeekOfYearCalendarUnit ) fromDate: testDate ]; int calandarWeek = [dateComponents weekOfYear]; uses a different algorithm. ISO definition: CW1 is the first week in the year containing 4 day, CW start on Mondays 回答1: I found out. It´s possible to configure the NSCalender: [cal setFirstWeekday:2]; //week starts on Monday [cal setMinimumDaysInFirstWeek:4]; //first week

Display NSDates in terms of week

风格不统一 提交于 2019-12-10 11:48:08
问题 Scenario: I have an expense tracking iOS Application and I am storing expenses from a expense detail view controller into a table view (with fetched results controller) that shows the list of expenses along with the category and amount and date. I do have a date attribute in my entity "Money" which is a parent entity for either an expense or an income. Question: What I want is to basically categorize my expenses for a given week, a month, or year and display it as the section header title for

Formatting Date to dd-MMM in iOS

泄露秘密 提交于 2019-12-10 11:13:36
问题 I've been searching this and couldn't quite find it. I have an object in a NSDictionary that contains a NSDate. Now standard NSDate objects are pretty long. and I want to show the user in dd-MMM format. For eg: The original date may be 2012-04-23 00:00:00 +0000 , for which I want the date to appear as 23 Apr I tried using NSDateComponents and NSDateFormatter but it didn't quite work. Probably I'm not figuring out the correct usage FOR the required format. Here's the code for better

Swift : Checking if 2 NSDates are the same

大兔子大兔子 提交于 2019-12-10 11:07:47
问题 Really simple one, I am sure this is a bug in swift. I am trying to check if 2 NSDates are the same. This statement never passes even thought the printout is below println("\(statistics.startDate) \(healthObject.date)") if healthObject.date.isEqualToDate(statistics.startDate) { healthObject.flights = Int(quantity.doubleValueForUnit(HKUnit.countUnit())) println(Int(quantity.doubleValueForUnit(HKUnit.countUnit()))) } 2015-03-30 13:56:50 +0000 2015-03-30 13:56:50 +0000 2015-03-30 13:56:50 +0000

Sort NSDictionaries in NSMutableArray by NSDate

僤鯓⒐⒋嵵緔 提交于 2019-12-10 10:59:14
问题 I have a NSMutableArray with dictionaries, all of the dict's contain a NSDate is form of NSString with key 'Date'. I want to sort the NSDictionaries by the Dates. So for example i have the following state of the array: Dict Date 20.06.1996 23:30 Dict Date 04.10.2011 19:00 Dict Date 20.06.1956 23:39 And I want to sort it, so that it looks like this: Dict Date 20.06.1956 23:39 Dict Date 20.06.1996 23:30 Dict Date 04.10.2011 19:00 I have already experimented with NSSortDescriptor, but without

Converting NSDate from a calendar to another

回眸只為那壹抹淺笑 提交于 2019-12-10 10:35:22
问题 I'm having trouble here. Took me hours but no use. Please keep in mind I checked the heck of StackOverFlow for a fix but there isn't any. When I convert the _date Object from Gregorian to Hijri it does not convert. I know that because when I print it it still gives me the Gregorian day. This troubles me because I want to setDate of a UIDatePicker and it's setting it incorrectly because the _date is gregorian and my UIDatePicker object calendar set to setCalendar:_hijriCalendar //DATE SETTING

How can I get the “internet time” on iOS? [duplicate]

无人久伴 提交于 2019-12-10 09:17:21
问题 This question already has an answer here : Is there any way to get the tamper-proof date and time on iPhone? (1 answer) Closed 5 years ago . So, I'm developing an app that is based on the time, but with NSDate an user can easily hack the application by changing system time of the device. So I might want to use a better method for retrieving time. How can I do this? Is there an easy way to retrieve time from internet? 回答1: Checkout this Google Library: https://github.com/jbenet/ios-ntp After

NSDate returns wrong year

孤街醉人 提交于 2019-12-10 09:07:26
问题 In MyappAppDelegate.m file at "application: didFinishLaunchingWithOptions:" method, I just wrote: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy"]; NSDate *date = [NSDate date]; NSLog(@"%@", [df stringFromDate:date]); return; And ran with iPhoneSimulator, console said: 2010-10-15 20:38:43.571 Myapp[59828:207] 0022 I can't understand what's happening. So I created new Xcode project and tested like above, then it correctly returned '2010'. Did I do some bad