nsdate

iPhone: Issue comparing a date between current date and sixty days from current date

烈酒焚心 提交于 2019-12-12 03:16:10
问题 I need to check an event date, which should be between Current date and 60 days from now. The below code is used, but it is NOT working correctly. Please note, i'm getting event string like this - "2012-04-14T16:50:02Z" from my server. // current date double currDateInMilliSecs = [NSDate timeIntervalSinceReferenceDate] * 1000; NSLog(@"currDateInMilliSecs: %f", currDateInMilliSecs); // sixty days double sixtydaysvalue = 60.0 * 24.0 * 3600.0 * 1000.0; NSLog(@"sixtydaysvalue: %f", sixtydaysvalue

Swift - Get next date from a array of weekdays

南笙酒味 提交于 2019-12-12 02:14:31
问题 Context I'm making an app where I have tasks with due dates and once they are done I want to set a new due date for according to a new date according to a day of the week repeat pattern chosen by the user. Im saving due dates as Date. Im saving the repeat pattern as Int32 (1 for Sunday, 2 for Monday, 4 for Tuesday...) but I can easily get it to an array of Strings or numbers representing each day Problem How do I get the next due date as Date (so I can repeat the task)? Example if I have a

NSDate from NSString , shows the previous day

ぃ、小莉子 提交于 2019-12-12 02:03:13
问题 I have s imple NSDate from NSString as below NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; issueDatabase.album_date = [dateFormatter dateFromString:albumXML.album_date]; but for some reason I'm getting the previous day instead of the current for eample if my albumXML.album_date is equal 2011-09-01 I'm getting the following stored in my database 2011-08-31 回答1: You need to set a timezone to your dateFormatter: [dateFormatter

Check if the current date string is within or outside the range of two other dates

我与影子孤独终老i 提交于 2019-12-12 01:55:40
问题 I have 2 date pickers. One is for selecting a start date and the other is for selecting an expiry date. When a selection has been made I convert the date to string format and store the results in a two text fields. This is how I save to the database: let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MMMM d" // e.g. September 15 let sDate = dateFormatter.dateFromString(startDateField.text) as NSDate! let eDate = dateFormatter.dateFromString(expiryDateField.text) as NSDate!

Sorting table sections by NSDate

女生的网名这么多〃 提交于 2019-12-12 01:54:01
问题 How do I sort NSDate so that if a time on a date is 05:00 Sunday morning, it stays on Saturday "night", but last on the list? I sort my tableview sections by date from JSON data [[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"fodboldStream", @"command", nil] onCompletion:^(NSDictionary *json) { //got stream //NSLog(@"%@",json); [[API sharedInstance] setSoccer: [json objectForKey:@"result" ]]; games = [json objectForKey:@"result"]; sections =

iPhone: How to Sort Dates Using NSDate?

你离开我真会死。 提交于 2019-12-12 01:45:56
问题 I have to sort objects based on NSDates. What are the options for sorting by NSDate? 回答1: In general you use a NSSortDescriptor to define the sort of collections like arrays or Core Data. You call the sort from the collection object itself. NSDate itself has comparison functions if you want to do the sort directly yourself. 回答2: You can do sorting of date by comparing two dates.For that you should use. NSComparisonResult class. NSComparisonResult result=[date1 compare:date2]; if result=

NSDate dateWithTimeIntervalSince1970 NOT returning GMT/UTC time

China☆狼群 提交于 2019-12-12 01:45:08
问题 I tried an experiment because I need to be able to generate a unix timestamp (since 1970) in the app I am working on. NSLog(@"Getting timeIntervalSince1970"); double theLoggedInTokenTimestampDateEpochSeconds = [[NSDate date] timeIntervalSince1970]; This should've returned epoch seconds (since 1970) in GMT (Seconds since Jan 1, 1970). However, when conducting the experiment at at Mon Aug 15 09:54:30 2011, it returned 1313427270.504315 Testing this with a simple perl one-liner on my Mac OS

extract date ranges grouped by day from time intervals

爱⌒轻易说出口 提交于 2019-12-12 01:14:19
问题 I want to extract date ranges grouped by day from 2 time intervals. For exemple, from: let startDateTimeInterval: NSTimeInterval = 1462060790 // "2016-04-30 23:59:50 +0000\n" let endDateTimeInterval: NSTimeInterval = 1462183200 // "2016-05-02 00:00:10 +0000\n" I want to get: 9 seconds // "[2016-04-30 23:59:50 => 2016-04-30 23:59:59] 86399 seconds // "[2016-05-01 00:00:00 => 2016-05-01 23:59:59] 10 seconds // "[2016-05-02 00:00:00 => 2016-05-01 00:09:59] I accomplished it but I am wondering if

NSDateFormatter dateFromString conversion

人走茶凉 提交于 2019-12-11 20:29:10
问题 I am having problems with conversion of NSString object to NSDate. Here is what I want to do: I am downloading an RSS Message from the internet. I have the whole message parsed by NSXMLParser. After that, I have parts like , or saved to particular NSStrings. I want to convert element (that includes publication date of RSS Message) to NSDate so that I could perform some operations on it like on a date object (e.g. sorting, showing on a clock etc.). Here is the way my looks like: "Wed, 25 Sep

How to get NSDate with nil value

橙三吉。 提交于 2019-12-11 20:22:18
问题 I'm a beginner in Swift and coding in general. Right now I'm trying to develop the piece of the code to set up the time limit for the action only once a day. @IBAction func yesButtonPressed(sender: AnyObject) { //To retrive the control date value. First time it has nil value var controlDate = NSUserDefaults.standardUserDefaults().objectForKey("controlDate") as? NSDate //To check current date to compare with var currentDate = NSDate() // To check if time interval between controlDate and