Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 6 NSDateFormatter stringFromDate: empty day of week

I'm having an issue with obtaining the full name for the day of week in iOS 6 NSDate object (in iOS 7 works fine). I've searched stackoverflow for similar issues but I didn't find what I was looking for.

My test case is:

formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EEEE"];
[formatter setDoesRelativeDateFormatting:NO];

NSDate *testDate = [NSDate dateWithTimeIntervalSince1970:1384551041.389218];
NSLog(@"%@",[formatter stringFromDate:testDate]);

The expected output is Friday (localized to your device region format and on a gregorian calendar), it works on iOS 7 but on iOS 6 it returns an empty description. I've tested in actual devices with the same region format set.

As far as I know, iOS 6 uses tr35-25 formatting according to this documentation, and the EEEE specifies full name day of week in that format.

Am I missing something?

like image 552
ZeCodea Avatar asked Mar 21 '23 14:03

ZeCodea


2 Answers

That actually looks like a bug in NSDateFormatter on iOS 6. However, it seems that the bug occurs only if you explicitly set

[formatter setDoesRelativeDateFormatting:NO];

If you omit that line (and NO is the default anyway) then the result is OK (at least when I tested it).

Remark: I assume that setDoesRelativeDateFormatting is only meant to be used in connection with setDateStyle:, but that is pure guessing.

like image 188
Martin R Avatar answered Apr 25 '23 09:04

Martin R


If you remove [formatter setDoesRelativeDateFormatting:NO]; from your code then you will get the result in both iOS 6.0 and iOS 7.0

like image 34
Pradhyuman sinh Avatar answered Apr 25 '23 08:04

Pradhyuman sinh