nsdate

How to sort NSMutableArray of date objects

烂漫一生 提交于 2019-11-30 05:51:27
问题 I'm doing some small work on sorting the date strings in the NSMutableArray, i'm getting the array from the sqlite db. If you print the array it is showing like this date strings are ( "2011-05-01", "2011-02-01", "2012-01-08", "2012-05-08", "2010-01-09 ) I want to show the dates in ascending order. Please help me out guys..... I'm newbie to objc.. 回答1: First you should convert all date Strings (which is NSString ) objects to NSDate objects and then sort these dateObjects . I believe you have

Swift 3.0 : Convert server UTC time to local time and vice-versa

给你一囗甜甜゛ 提交于 2019-11-30 05:50:27
问题 I want to convert server UTC time to local time and vice-versa. Here is my code.. var isTimeFromServer = true var time:String! var period:String! let timeString = "6:59 AM" //Current UTC time if isTimeFromServer { let index = timeString.index(timeString.startIndex, offsetBy: 5) let twelve = timeString.substring(to: index) var dateString:String! let dateFormatter = DateFormatter() dateFormatter.dateFormat = "H:mm" let date12 = dateFormatter.date(from: twelve)! dateFormatter.dateFormat = "h:mm

Comparing certain components of NSDate?

 ̄綄美尐妖づ 提交于 2019-11-30 05:35:42
问题 How would I compare only the year-month-day components of 2 NSDates ? 回答1: So here's how you'd do it: NSCalendar *calendar = [NSCalendar currentCalendar]; NSInteger desiredComponents = (NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit); NSDate *firstDate = ...; // one date NSDate *secondDate = ...; // the other date NSDateComponents *firstComponents = [calendar components:desiredComponents fromDate:firstDate]; NSDateComponents *secondComponents = [calendar components

NSDate returns wrong date on the first of month

[亡魂溺海] 提交于 2019-11-30 05:32:50
问题 My app used [NSDate date ] function to get current date. Its work fine other days except 1st of every month during AM . i.e Follow Following steps : Set the system date as 01 - June - 2011 & time between 00.00 midnight to 5.59 AM. Use following code : NSLog(@"Current Date :: %@",[NSDate date]); The O/P is :: Current Date :: 2011-05-31 19:40:21 +0000 Desired O/P is :: Current Date :: 2011-06-01 00:00:0( i.e.the time which is set ) +0000 Also From 6 AM it works fine. What is reason for this?

dateWithTimeIntervalSince1970 not returning correct date

我们两清 提交于 2019-11-30 05:24:33
问题 I have the following method below that is meant to retrieve and convert a unixTimeStamp from an API call to a NSDate object that I can easily manipulate and use. For some reason, this returns wrong values. An example would be when the unixTimeStamp is 1385152832, the date SHOULD be Fri, 22 Nov 2013 20:40:31 GMT November 22, 2013 at 3:40:31 PM EST but instead spits out: 45852-09-07 08:13:52 EST. Does anyone know why this would happen? -(NSDate *)messageDate { NSTimeInterval unixTimeStamp = [

How can I format a date in Objective-C similar to the jquery.timeago library?

与世无争的帅哥 提交于 2019-11-30 04:47:41
I have a feed of items displayed in table cells, part of which is a date / timestamp in the past. In Objective-C, how can I accomplish formatting them in the same manner as the jquery.timeago plugin on the web? That is, taking in a date and outputting things like: 'just now' '2 minutes ago' '24 days ago' 'a month ago' I see there is an NSDate extension class here with methods such as dateWithDaysBeforeNow, dateWithMinutesBeforeNow, etc, but if there is a library out there that has already done this I will use it. EDIT: Further to this, if someone composes a method (takes a date, returns a

create a NSDate from a string

[亡魂溺海] 提交于 2019-11-30 04:31:44
I have an NSString like this: @"3/15/2012 9:15 PM" and I would like to convert it to NSDate , I have done like this: NSString *str =@"3/15/2012 9:15 PM"; NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateFormat:@"mm/dd/yyyy HH:mm"]; NSDate *date = [formatter dateFromString:]; NSLog(@"%@", date); // date = null Can you help me please, thanks. Ilanchezhian Use the following solution NSString *str = @"3/15/2012 9:15 PM"; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"MM/dd/yyyy HH:mm a"; NSDate *date = [formatter dateFromString

Creating a Time Based Reminder App in iPhone

佐手、 提交于 2019-11-30 04:08:25
I am working on time based reminder App. in which the user enter his reminder and time for the reminder. The problem is that how to continuously comparing the current time with the user defined time. Any sample code will greatly help. because i am stuck on this point. valvoline Comparing the current time vs. the user defined one is not the right design pattern. UIKit offers the NSLocalNotification object that is a more high-level abstraction for your task. Below is a snip of code that create and schedule a local notification at the choosen time: UILocalNotification *aNotification = [

Cocoa - Localized string from NSDate, NSCalendarDate

杀马特。学长 韩版系。学妹 提交于 2019-11-30 04:07:59
I'm using NSDate to get a string such as "18 Jun 09", with code: NSDate *theDate = [NSDate date]; NSString *dateString = [theDate descriptionWithCalendarFormat:@"%d %b %y" timeZone:nil locale: nil]; This works, but only results in an English output. I need the output to be localized in the user's default language. Does Cocoa (Mac OS X 10.4, 10.5 in this case) provide a facility for this localization or do I have to manually localize for each case of day and & month names my self? (I have provided a locale, but although that does provide a locale-specific ordering of the date, it does not

NSPredicate and CoreData - decide if a Date attribute is “today” (or between last night 12am to tonight 12am) on iOS

我与影子孤独终老i 提交于 2019-11-30 03:45:45
问题 I'm using a NSFetchedResultsController and a UITableViewController to populate a UITableView from a CoreData database. I have a NSDate object saved into this Date attribute labeled "startTime". Then I'm trying to only pull todays's data by using a NSPredicate that looks like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startDate == %@", todaysDate]; I'm getting zero results. I understand this because a NSDate object just hold the number of seconds or milliseconds or