nsdate

NSDate to RFC 2822 Date format

冷暖自知 提交于 2019-12-07 11:22:07
问题 Is there any efficient way to convert an NSDate to RFC 2822 Date format string ? I want to use this string to create an NSURLRequest and set the value of "If-Modified-Since" header field. 回答1: try to use an NSDateFormatter NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // maybe there exist a new-method now dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss Z"; //RFC2822-Format NSString *dateString = [dateFormatter stringFromDate:myDate]; 回答2: Swift 3 let rfcDateFormat =

iOS - how to compare two times?

南楼画角 提交于 2019-12-07 10:15:26
问题 I use the following function to check if a message has expired - - (BOOL) hasExpired:(NSDate*)myDate { if(myDate == nil) { return false; } NSDate *now = [NSDate date]; return !([now compare:myDate] == NSOrderedAscending); } This works fine if I am comparing two different dates. However, it returns false if the message has expired earlier in the day today. Any ideas on how I might fix it? 回答1: (Adding my comment as an answer:) This should not happen, also 1 second difference between NSDate

Converting a date by string format to nsdate result one day before string date

自闭症网瘾萝莉.ら 提交于 2019-12-07 07:55:07
问题 I searched about my problem but I did not find any help related... The story: The user create a continues event by name, start date, end date and note, so saves all fields on the Sqlite database. The both dates format are "yyyy-MM-dd". After that, when user want to do an action on event, the app checks the date that user selected by start and end date and if the entered date is before start date or after end date notifies user. The problem: I, as an user, created an event from 18-8-2012 to 18

NSDate as keys for NSDictionary

坚强是说给别人听的谎言 提交于 2019-12-07 07:10:24
问题 Is it possible to add NSDate as keys and some arrays as it values in a NSDictionary? I dont have any requirement of writing the dictionary to disk - archiving or unarchiving, just as this guy needs it: NSDictionary with NSDates as keys But, why I want NSDate to be added as keys specifically is so that I can fetch all keys from the dictionary and do some computations like, fetching the dates from within a range. Whether two objects with same date value share same memory when created? Is it

Weekday of first day of month

拈花ヽ惹草 提交于 2019-12-07 06:58:11
问题 I need to get the weekday of the first day of the month. For example, for the current month September 2013 the first day falls on Sunday. 回答1: At first, get the first day of current month (for example): NSDate *today = [NSDate date]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components = [gregorian components:(NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit) fromDate:today]; components.day = 1; NSDate

Notification in Swift every day at a set time? [duplicate]

删除回忆录丶 提交于 2019-12-07 06:58:05
问题 This question already has an answer here : UILocalNotification always shows up as soon as I load my app regardless of the fire date (1 answer) Closed 4 years ago . If anyone gets confused and thinks that this is a duplicate of my question from yesterday, it's not. There I was asking how to call a function every day, here I am asking how to call a notification at a specific time every day. I am looking for a way to repeat a local notification every day at 7.00AM. I currently have this code

Whither NSDate dateByAddingTimeInterval on iPhone OS?

可紊 提交于 2019-12-07 05:31:03
问题 Greetings! I must be seeing things. Look at this excerpt from the iPhone OS reference library: addTimeInterval: Returns a new NSDate object that is set to a given number of seconds relative to the receiver. (Deprecated. This method has been replaced by dateByAddingTimeInterval: .) However, it is nowhere to be found in the docs, nor in the headers. If I look at the Mac OS SDK, then I find it. Typo? Just keep using addTimeInterval: after all?? 回答1: It's actually an error in the docs.

iOS - Not able to store NSDate into NSUserDefaults

久未见 提交于 2019-12-07 02:50:48
问题 In my application, i want to store the date at which the app is started for the first time. I'm using following code in application:didFinishLaunchingWithOptions method NSDate* today = [NSDate date]; [[NSUserDefaults standardUserDefaults] registerDefaults: @{@"CONSCIENCE_START_DATE" : today}]; NSLog(@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"CONSCIENCE_START_DATE"]); But every time when i start the application, its printing the time at which the app is starting. Its not

change NSDate from one time zone to another [closed]

大城市里の小女人 提交于 2019-12-06 17:47:56
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Given a date in NSString like "2012-12-17 04:36:25" (which is GMT) how one can simply change it to other time zones like EST, CST All

NSDate hebrew date label

我是研究僧i 提交于 2019-12-06 16:44:06
I make label with the date for today but I need hebrew date for today. this my code NSDate *today = [NSDate date]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateStyle:NSDateFormatterShortStyle]; NSString *dateString = [dateFormat stringFromDate:today]; [_label setText:dateString]; I not build calendar this label with date for today. Thanks! Assuming the user's current locale is not set for Hebrew, then you need to ensure the date formatter's locale is set for Hebrew, NSLocale *hebrew = [[NSLocale alloc] initWithLocaleIdentifier:@"he_IL"]; // Hebrew, Israel