nsdateformatter

iPhone SDK Objective-C __DATE__ (compile date) can't be converted to an NSDate

//NSString *compileDate = [NSString stringWithFormat:@"%s", __DATE__]; NSString *compileDate = [NSString stringWithUTF8String:__DATE__]; NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease]; [df setDateFormat:@"MMM d yyyy"]; //[df setDateFormat:@"MMM dd yyyy"]; NSDate *aDate = [df dateFromString:compileDate]; ...

How to change format of date/time?

I have this date and time format: 2010-05-19 07:53:30 and would like to change it to: Wednesday @ 7:53PM 5/19/2010 I'm doing this, which gets the current format: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; but when I change the format, I end up with a null. For exa...

NSDateFormatter return nil on 2 different input which in same format!?

Hi all! I am newbie of objective-c and i got this crazy problem… for low precision test case: dateString = @"2010-05-25 11:05:21", conversion success. dateString = @"2010-03-01 15:54:36", conversion fail. for high precision test case: dateString = @"2010-05-25 11:05:21.937113", conversion success. dateString = @"2010...

Format a date from a string

Hey. I'm trying to format a date from a string into another format. For example: 2012-05-29 23:55:52 into 29/05 *newline* 2010. I just don't get the logics behind NSDate and NSDateFormatter, I think.. Any help will be appreciated. Thanks :) ...

NSDateFormatter - set device language as locale?

Hey. I'm trying to get the iPhone to display dates formatted by an NSDateFormatter in the current device language. I have tried setLocale:[NSLocale currentLocale], but that only returns 5 instead of May (or Mai, as I want it to be). EDIT: currentLocale shows May (english). systemLocale shows 5 (I think systemLocale is Norwegian), and ...

I'm 532 hours away from GMT????

iPhone, Xcode, Objective-c: NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease]; [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *s = @"1902-02-01 01:00:00"; NSDate *aDate = [df dateFromString:s]; NSLog(@"(%@)", aDate); // (1902-02-01 01:00:00 -053211) Wow.. 532 hour timezone offset? ...

What's wrong with how I'm using NSDateFormatter?

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]; [dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss zzz"]; NSString *dateString = @"Tue, 08 Jun 2010 17:00:00 EDT"; NSDate *eventDate = [dateFormatter dateFromStrin...

Date of the start of the current week (If weeks always start on Sunday)

I'm not sure if this is the best way to do this... but... I need to get the date/time since: Midnight at the start of today Midnight at the start of the current week (Sunday) Midnight at the start of the current month Midnight at the start of the current year I use the NSDateFormatter: [df setDateFormat:@"yyyy-MM-dd 00:00:00"]; strDa...

How to convert a string into an NSDate?

Let's say I have something like 30-10-2025 12:53, how could I convert that to an NSDate? I guess there's some class that takes this plus an format string that tells it how the date looks as a string, so it can parse it... where must I look? ...

Why does NSDateFormatter not parse this date?

NSString *dateStr = @"2010-06-07 19:30:18"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-DD hh:mm:ss"]; NSDate *date = [dateFormatter dateFromString:dateStr]; date is always nil. But the date format seems to be correct. What's wrong? Edit: Seems to work with @"yyyy-MM-DD HH:m...

Where to look up the date format specifiers used in cocoa / cocoa touch?

For example: [dateFormatter setDateFormat:@"yyyy-MM-DD HH:mm:ss"]; I guess there's a list somewhere that shows all those date format specifiers, but can't find any. The NSDateFormatter docs seem to not mention these. ...

iPhone NSDateFormatter Timezone Conversion

I am trying to create a formatter that will convert the date format shown to an NSDate object: NSString *dateStr = @"2010-06-21T19:00:00-05:00"; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"]; NSDate *date = [dateFormat dateFromString:dateStr]; The issue is the ti...

NSDateFormatter returning nil in OS 4.0

I had the following code working on on OS 3.x NSString *stringDate = @"2010-06-21T20:06:36+00:00"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate *theDate = [dateFormatter dateFromString:stringDate]; NSLog(@"%@",[dateFormatter stringFromDate:theDate]); b...

is NSDateFormatter dateFromString: supposed to return nil for an invalid string?

According to the class reference, dateFromString method returns "A date representation of string interpreted using the receiver’s current settings". Using the following code: NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]...

dateformatter works in simulator but not on device

Hi, this code works on simulator ... but not on my ipod touch... on ipod I see the unformated date :-( NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] retain]; //Date Before = Sun, 20 Jun 2010 06:00:00 +020 [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"]; NSDate *d = [formatter dateFromString:...

iphone: date formatter on 4.0

Hello, until now I used date formatter the following way with string like '2010-06-10T11:50:01+02:00': NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate *from = [dateFormatter dateFromString:[NSString stringWithString:fromStr]]; That wa...

NSDateFormatter problem with increased Date

hi, im trying to increase a date and get a formatted output for every month ... it works fine, but the step Dec 2010 to Jan 2011 doesn't work. please have a look at this: NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; NSDate *lastDate = [[NSDate alloc] init]; for (int i = 0;...

NSDateFormatter's init method is deprecated?!?!

Per http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html The init method of NSDateFormatter is "Available in iPhone OS 2.0 through iPhone OS 3.2", and therefore not in 4.0. Now, it certainly works, but this seems odd. Is this is a mistake or is there...

Date Picker working differently on 3GS than 3G, touch and iPad

My app hit the app store today. I had a user submit a weird bug. I have a date picker that passes back a date that I store as a string in SQLite. I tested the app on the simulator, a 3G, a itouch, and an iPAD. On all of these, it works as expected. However, on this user's 3GS it adds a day to the date selected in the date picker. I...

For iPhone OS 4.0 "dateFromString" method of NSDateFormatter returns nil.

Hi I am using following code & its working perfectly fine in iPhone OS 3.2 +(NSDate *)NSDateFromString:(NSString *)dateString { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterShortStyle]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; [dateFormatte...