nsdateformatter

Using NSDateFormatter to format date to local date

I have tried numerous attemps of formatting a relatively simple date format to a date object, but also converting to my local time zone. All dates are formatte like this: 2010-09-11T08:55:00. This is GMT time, and I want it converted to a date object with GMT+2. Can anyone please point me in the right direction? ...

Convert NSDate to NSString with NSDateFormatter with TimeZone without GMT Time Modifier

I'm initializing my NSDateFormatter thusly: NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; [dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss z"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSeco...

NSDate format in iOS 4.1

Hi All, [NSDate date]in iOS 4.0 used to return date in the format: 2010-09-15 09:28:26 +0530 but now in iOS 4.1 it returns the date in the format: 2010-09-15 09:28:26 GMT In my application it is leading to lots of problems. Does anyone know how to fix this? Thanks in advance, YPK ...

NSDateFormatter is showing wrong date format (nachm. instead of PM) in the simulator

Why does the simulator is showing me 10:30 nachm. instead of 10:30 PM? I use the following code: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat: @"h:mm a"]; NSLog(@"%@",[dateformat stringFromDate: myDate]); OK I think I have to set a Locale somewhere ... ...

I have an exact string as say "November 4, 2010" and I want to compare it with today's date in iPhone?

How can one convert a string "November 4, 2010" and not "MMMM d, YYYY" to NSDate for comparison? ...

parsing date works on simulator not iphone??

I have the following code to parse a date from string: NSString * str = @"8/13/2010 1:59:00 PM"; NSDateFormatter * dateFormat2 = [[NSDateFormatter alloc] init]; [dateFormat2 setDateFormat:@"MM/dd/yyyy h:mm:ss a"]; NSDate * orderDate = [dateFormat2 dateFromString:str ]; but orderDate is always coming up null, what am i doing wrong ? Wh...

Date and time zone problems in Cocoa

I hav a string e.g. 2010-09-24. Now I want this string read as it is in an other timezone as I am. So I create an NSDateFormatter and set it's time zone e.g. to Europe/Berlin. What I get back is an NSDate object adjusted (2010-09-23 18:00:00) to my local time zone (e.g. America/New_York). But I want an NSDate in the time zone Europe/Be...

NSDateFormatter when iPhone set to 12-hour clock

I'm using an NSDateFormatter to format an NSDate to be in the format "HH:mm 'on' dd MMMM YYYY". This is the code I've written: [dateFormatter setDateFormat:@"HH:mm 'on' dd MMMM YYYY"]; [dateFormatter setLocale:[NSLocale currentLocale]]; Then I'm updating a label to display "Data from 12:45 on 22 September 2010", using the method stri...

How can I make a NSDateFormatter accept input in one format and display it in another?

I have a table view that displays dates using a NSDateFormatter to format them using the Full date style (today would be formatted as "Friday, September 24, 2010" or in German "Freitag, 24. September 2010"). But when editing the date the formatter forces the user to type the date in the same format. How can I make the formatter accept da...

Date is getting changed while converting to NSDate from NSString.

Hi all, I am converting NSString to NSDate with help of NSDateFormatter. Now code works fine here in all OS with device & simulator but it is creating different Output at UK, USA region. Here is the code that I am using. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"...

NSDateFormatter - 1 day incorrect?

Hi. I am importing a CSV file with a date format of month/day/year (e.g. 21/01/2007). I am looping through the CSV some are working but some are coming out with the date 1 day previous with a time of 23:00? One of the dates that are not working would look like this: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; ...

NSDateFormatter returns a date off by a day

In my iPhone app, I am trying to get the EEE MMM dd from a date string received by a web service. For all dates where time is < 07:00, the NSDateFormatter returns a date off by 1 day. For example: Date to format: 2010-11-17T05:00:00, formatted date result: Tue Nov 16 Here's the code snippet: NSDateFormatter *dateFormat = [[NSDateForma...

UIDatePicker & NSDateFormatter returning incorrect date

Hello, I have allready tryed solutions from a few posts, but no luck. The problem is that i'm facing is probably whit time zones. Both on device and simulator UIDatePicker and NSDateFormatter are returning incorrect dates, adding or substracting the difference from GMT 0, from the selected date (according to the current time zone set on ...

How to get seconds elapsed from a Date String?

In objective-C, I want to determine the seconds elapsed from a date string such as: "Sat, 09 Oct 2010 06:14:50 +0000" How do I do this? I got lost in the convoluted descriptions of NSDateFormatter. ...

NSDateComponents incorrectly reporting day

Hi all, I have a feeling this is due to some time zone not being set or something this is what I have: NSDateComponents *theComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:workingDate]; NSLog(@"%d", theComponents.day); [theComponents setDay:3]; NSLog(@"%d", theComponents.day); se...

How to convert today's date into Day of the Year for iPhone?

I am trying to do this in Xcode... Today's Date = Day of the year October 13th = 303 (I think) January 1st = 1 December 31st = 365 NSDate to get todays date, then I'm out of idea =( ...

NSDateformatter give 'null' on iPhone, correct date on iPad

Could anyone explain this to me? I've seen quite a few DateFormatter issues around, and all seem to be related, but not exactly what I'm facing here. Consider the following code: NSString * CleanDate = @"20101117T020000-0000"; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyyMMdd'T'HHm...

Objective C - NSDateFormatter returns nil ??

NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.sss"]; self.date = [dateFormatter dateFromString:dateString]; the code works fine with this string "2007-06-10 06:31:54.935" but doesn't work with this one (it returns nil if the time is set to 0): "20...

Date issue with Georgian Calendar previous day date shown

I had some issue with date: I get the current date (2010-10-27) in NSDate,converting it to NSString ...it's k But again when I try to get the date from String i.e NSDate , I am always getting the day before date . i.e (2010-10-26) instead of getting (2010-10-27). Plz help me.....I tried alot for the same..with every possibilty Here is...

Convert 24h to 12h time format in Obj-C

I currently display time in 24h format, because it's the easiest thing for me to do right now with the data I have. I get the time in "minutes since midnight", so for example, 07:00 or 7:00 a.m is "420" and 21:30 or 9:30 p.m is "1290" and so on. [NSString stringWithFormat:@"%02d:%02d - %02d:%02d", (open / 60), (open % 60), (close / 60)...