NSDateFormatter with 24 hour times
I have a countdown timer which countsdown from the current date/time to a specific future date/time. It is working great except for one problem. I input the future date using NSDateFormatter and dateFromString. It doesn’t seem to be able to accept any time (hour) over 12 though indicating it is not support 24 hour clock. […]
Convert ISO 8601 to NSDate
I have a timestamp coming from server that looks like this: 2013-04-18T08:49:58.157+0000 I’ve tried removing the colons, I’ve tried all of these: Converting an ISO 8601 timestamp into an NSDate: How does one deal with the UTC time offset? Why NSDateFormatter can not parse date from ISO 8601 format Here is where I am at: […]
Convert NSString of a date to an NSDate
This might be a silly question, but I can’t seem to find the answer on here or in the documentation. I want to convert an NSString such as @”9/22/2010 3:45 PM” to an NSDate. I know to use NSDateFormatter, but the problems are The month could be one or two digits Likewise, the date could […]
NSDateFormatter and yyyy-MM-dd
I’m trying to take a NSString date in the format “2/22/11” and convert it to this format: 2011-02-22 This is my code: NSDate *dateTemp = [[NSDate alloc] init]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@”yyyy-MM-dd”]; dateTemp = [dateFormat dateFromString:newInvoice.date]; newInvoice.date = [dateFormat stringFromDate:dateTemp]; newInvoice.date starts as an NSString equal to “2/22/11”. dateTemp ends up […]
NSTimeInterval to NSDate
How can I convert a NSTimeInterval to NSDate? Think of it like a stopwatch. I want the initial date to be 00:00:00, and I have a NSTimeInterval of X seconds. I need to do it like this because the NSTimeInterval needs to be converted to an int by using lround to round up, then converted […]
How to change the format of date in date picker
In my iPhone app, I need to display date in yyyy/MM/dd format as show in beloow image but in iPhone Date picker it is in the format of MM/dd/yyyy which is not in uniform for my application I tried with changing the local values (with different country regions) of the Date picker but no use […]
How do you calculate the day of the year for a specific date in Objective-C?
This is something I found myself spending hours to figure out and therefore want to share with you. The question was: How do I determine the day of the year for a specific date? e.g. January 15 is the 15th day and December 31 is the 365th day when it’s not leap year.
Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate?
If I use the following code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@”yyyy-MM-dd’T’HH:mm”]; NSDate *myDate = [dateFormatter dateFromString:@”2010-01-28T15:22:23.863″]; NSLog(@”%@”, [dateFormatter stringFromDate:myDate]); It is successfully converted to a Date object, however, I cannot seem to format it any other way than yyyy-MM-dd’T’HH:mm, i.e. what gets logged is 2010-01-28T15:22:23 If I change the dateFormat to say […]
NSDate Format outputting wrong date
I have a NSString (ex. “2011-04-12 19:23:39”), and what I did to format it to a NSDate was the following: [inputFormatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”]; NSDate *date = [inputFormatter dateFromString:newDateString]; but what it outputs when I nslog the date is this: 2011-04-12 23:23:39 +0000 which is about 4 hours off. Is there something I missed? Possibly a […]
iOS NSDateFormatter Timezone
I have some code that takes a string, turns it into a date, reformats it then spits it out as another string: [formatter setDateFormat:@”YYYY’-‘MM’-‘DD’,’HH:mm:ss’,’ZZZ”]; [formatter setTimeZone:[NSTimeZone timeZoneWithName:@”America/New_York”]]; NSDate *date = [formatter dateFromString:combinedString]; [formatter setDateStyle:NSDateFormatterLongStyle]; NSString *finishedString = [formatter stringFromDate:date]; Basically, it works fine except for the timezones. All of the input strings are in timezone […]