Reputation: 7
I've string @"Sun, 15 Jan 2012 17:09:48 +0000"
I want date from it..
What can I do
I tried
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"DDD, DD MMM YYYY HH:MM:SS +HHMM"];
NSDate *date = [dateFormat dateFromString:stringDate];
but date was nslogged with null
Upvotes: 0
Views: 351
Reputation: 12333
incorrect dateFormat:
, use this:
[dateFormat setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ"];
more on : http://unicode.org/reports/tr35/tr35-6.html#Time_Zone_Fallback
Upvotes: 1
Reputation: 57179
Your format is incorrect and here is why
Sun, 15 Jan 2012 17:09:48 +0000
DDD, DD MMM YYYY HH:MM:SS +HHMM
^^^ ^^ ^^^^ ^^ ^^ ^^^^^ < Treating the last 2 digits of the timezone as months
^^^ ^^ ^^^^ ^^ ^^ ^^^ < Treating the first 2 digits of the timezone as hours
^^^ ^^ ^^^^ ^^ ^^ ^ < Hardcoding the + (timezone can handle that)
^^^ ^^ ^^^^ ^^ ^^ < Using fractional seconds (not a big deal)
^^^ ^^ ^^^^ ^^ < Using months instead of minutes
^^^ ^^ ^^^^ < Using weak year instead of calendar year
^^^ ^^ < Using day of year instead of day of the month
^^^ < Using day of year instead of day of the week
Here is the correct format "EEE, dd MMM yyyy HH:mm:ss ZZZ"
Upvotes: 1
Reputation: 9977
Your date format is probably wrong. Check the documentation here:
http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
Try that: E, d MMM y HH:mm:ss Z
Upvotes: 0
Reputation: 8502
Well, there a couple things I see wrong. I think you need to review the date formatter guide: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1.
First off, the format is case sensitive. Soo... capital 'M' is month, lowercase 'm' is minute. Day is lowercase 'd'. Year is lowercase 'y'. There's probably other mistakes you've made but this should get you started in the right direction.
Upvotes: 0