Tag: nsdateformatter

Relative Date Formatting, output for past dates?

I am looking at using -[NSDateFormatter setDoesRelativeDateFormatting:] to present dates as “Today” or “Yesterday”. I am only looking at dates in the past but am curious what options I would see localised for the UK. Just “Today” “Yesterday” or anything more convoluted like “The day before yesterday” Are the possible outputs listed anywhere so I […]

converting string to NSDate issue: unrecognized selected

indexNumber.row is a date like 2012-03-09 23:00:00 +0000. I’ve tried a handful of different ways to get my date into an NSDate, but I keep getting the title error. NSString *inputString = [self.measurements objectAtIndex:indexNumber.row]; // Convert string to date object NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@”yyyy-MM-dd”]; NSDate *date = [dateFormatter dateFromString:inputString ]; NSLog(@”date format […]

change NSDate from one time zone to another

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 the steps I saw so far took so many unnecessary steps

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

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 = […]

Producing an NSDate with NSDateFormatter Yielding nil NSDate Value

I am trying to produce a date from a string with the following: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@”MMMM dd, yyyy HH:mm:ss”]; NSLog(@”ENDINGDATE: %@”, [closure objectForKey:@”ENDINGDATE”]); NSDate *tempDate = [dateFormatter dateFromString:[closure objectForKey:@”ENDINGDATE”]]; The ENDINGDATE NSLog produces the following: ENDINGDATE: April, 21 2011 20:00:00 Everything seems to be fine, so I am stumped as […]

Shared NSDateFormatter – Best Practices?

My team found that we were using a variety of NSDateFormatter objects throughout our code base, and started looking into how we could avoid the cost/confusion of allocating/initializing common formatters in a bunch of separate places. One idea we had was to create a category on the NSDateFormatter class that would provide a reference to […]

NSDate/NSDateFormatter – Storing only time, not date?

I’ve been looking around but I haven’t seen anything that addresses this so I’m hoping someone can help clear this up for me. What I am trying to do is use an NSDate variable(in core data) to store a time, not date and time, but just time in the format HH:MM:SS; After looking at the […]

NSDateFormatter relative date formatting with custom format

So my intention is to put out dates that would look like the following: Today, August 28 Tomorrow, August 29 Friday, August 30 …etc The issue is that it seems I can only get so close. When I setDoesRelativeDateFormatting:YES and setDateStyle to Full and setTimeStyle to None, it yields results like this: Today Tomorrow Friday, […]

NSDateFormatter in 12-hour mode

I have the following code. NSDateFormatter *df = …; [df setTimeZone:[NSTimeZone defaultTimeZone]]; [df setDateFormat:@”yyyy-MM-dd’T’HH:mm:ss.SSSZZZ”]; NSDate * date = [df dateFromString:date_string]; //here is the problem In 24-hour mode everything is ok. When 12-hour mode is set on device, stringFromDate returns null. Format of date_string is the same all the time, date format too. Why does it […]

Objective-C: Unicode Date Format

I am trying to work out how to have the UNICODE representation of Sun, 03 May 2009 19:58:58 -0700 as eee, dd MMM yyyy HH:mm:s ZZZZ or something. I can’t seem to get this working precisely.