nsdate

Swift displaying the time or date based on timestamp

若如初见. 提交于 2019-12-06 16:43:39
I have an API that returns data including a timestamp for that record. In swift I have the timestamp element loaded and converted into a double and can then convert that into time. I want to be able to return the time if the date of the record is today and return the date if the record is not today. See below: let unixTimeString:Double = Double(rowData["Timestamp"] as! String)! let date = NSDate(timeIntervalSince1970: unixTimeString) // This is on EST time and has not yet been localised. var dateFormatter = NSDateFormatter() dateFormatter.timeStyle = .ShortStyle dateFormatter

Core Data sort tableview by formatted date

不羁的心 提交于 2019-12-06 16:05:04
I know how to sort Core Data objects in a tableview by NsDate, but this by default seems to create a new section for each object. I want to sort them by a medium formatted date with NSDateFormatter. How would I do this? For example, if I have 3 objects created on the same day, I want them to be in the same section with the section title being that Day, no time needed. Each object has an NSDate property. Thanks for your help. This is the code I have in fetchedResultsController with rgeorge's suggestions. What am I missing here? - (NSFetchedResultsController *)fetchedResultsController { if

Get name of days between two date in ios?

你。 提交于 2019-12-06 15:50:16
How to get name of days between two dates in ios? Example: Input: Start Date: 3-11-2012 End date: 5-11-2012 Output: 3-11-2012 Wednesday 4-11-2012 Thursday 5-11-2012 Friday Thanks.. try this, NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd"]; NSDate *startDate = [df dateFromString:@"2012-07-20"]; // your start date NSDate *endDate = [NSDate date]; // your end date NSDateComponents *dayDifference = [[NSDateComponents alloc] init]; NSMutableArray *dates = [[[NSMutableArray alloc] init] autorelease]; NSUInteger dayOffset = 1; NSDate *nextDate = startDate; do {

objective-c: Conversion between TimeZones

ⅰ亾dé卋堺 提交于 2019-12-06 14:51:52
问题 I'm having problems converting a time string to a different timeZone. This is a string example as the one I retrieve from a server: @"5/14/2013 4:19am" I know the timeZone is America/New_York and I want to convert it to my local timeZone: Europe/Rome. Here is the code I wrote to test it: -(void) convertTimeZone { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.timeZone=[NSTimeZone timeZoneWithAbbreviation:@"GMT"]; dateFormatter.dateFormat=@"MM/dd/yyyy HH:mma";

NSDateFormatter not behaving properly when converting from Buddhist calendar to Gregorian calendar date formats

可紊 提交于 2019-12-06 14:35:09
问题 I'm making an app that supports conversion of dates from the Buddhist calendar to Gregorian (Note: The "General > International > Calendar" settings of the device I'm testing on is "Buddhist".). However, I can't figure out why the NSDateFormatter doesn't parse my dates properly. Here's my code: NSDate *now = [NSDate date]; NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter

NSDateFormatter giving me time 4 hours ahead

核能气质少年 提交于 2019-12-06 13:35:47
问题 I'm converting a string "Jun 11, 2012 9:30 PM" to an NSDate and I keep getting 4 hours ahead for some reason. The funny thing is I'm using this same string to feed a UIDatePicker in a detailed view where I have to do the same conversion, and the UIDatePicker renders the time fine. Only when I now try to NSLog it in my main and detailed view do I have problems. This is in my views : NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MMMM dd, yyyy h:mma"];

finding NSDate's in an NSArray that have a time of day after a given time (e.g. 8pm)?

强颜欢笑 提交于 2019-12-06 13:29:55
Is there a quick way in Objective-C of identifying NSDate's in an NSArray that have a time of day after a given time (e.g. 8pm)? I can't quite see anyway other than manually walking through each NSDate in the array and then using NSDateComponents to break out the hour/minute/second...Not even sure if there is a simple way to get the time from an NSDate in a fashion that represents a fraction of 24hours, as this might help a little. (e.g. 6pm would be 18/24 = 0.75 in this case) There is no need to break in NSDateComponents . NSTimeInterval interval = [date1 timeIntervalSinceDate:date2]; if

Sort NSDictionaries in NSMutableArray by NSDate

我的未来我决定 提交于 2019-12-06 13:23:43
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 success... Update: I have managed to sort the dates, but I came to this problem: In the dicts there is

Get weekdays within a month

不打扰是莪最后的温柔 提交于 2019-12-06 13:19:02
问题 I'm trying to get the dates within a given month. My plan is to Get the start and the end dates of a given month,. Get all the dates that fall within that range. Iterate through them and eliminate dates that fall within a weekend using the isDateInWeekend method. The remaining dates are the weekdays. So I created two NSDate extension methods to get the start and the end dates of the month. extension NSDate { var startOfMonth: NSDate { let calendar = NSCalendar.currentCalendar() let components

Can I use NSDateFormatter to convert this date string to an NSDate?

走远了吗. 提交于 2019-12-06 13:16:48
I have this string... 2010-08-24T16:00:00-05:00 and I'd like to extract the time portion from it (i.e. 16:00) and convert it to its 12-hour equivalent (i.e. 04:00 pm). I'm trying to use NSDateFormatter to accomplish this, but it's not working... NSDateFormatter* dateformatter = [[NSDateFormatter alloc] init]; [dateformatter setDateFormat:@"hh:mm a"]; NSDate *date1 = [dateformatter dateFromString:[listOfTimes objectAtIndex:0]]; [dateformatter release]; Can I use NSDateFormatter with this date format? If not, how can I extract the time and convert it to its 12-hour time equivalent? Thanks!