16

I have two text, one in Hebrew language and one in English.

In first text I have date that is in Hebrew.

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSLocale *hebrew = [[NSLocale alloc] initWithLocaleIdentifier:@"he_IL"]; // Hebrew

    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'hh:mm:ss.SSSZ"];

    NSDate *date = [dateFormatter dateFromString:model.startDate];

    NSLog(@"%@", date);

    [dateFormatter setDateFormat:@"EEEE,dd.MM.yyyy"];
    dateFormatter.locale = hebrew;
    NSString *strDate = [dateFormatter stringFromDate:date];

and start Date is : יום שישי,19.08.2016 in NString object strDate

On other hand I have text 07: 00-16: 00 in NSString object timeForRequest

My needed format is יום שני, 15.01.2016 | 16:00 - 07:00

and when I try to do same with following code

[NSString stringWithFormat:@"%@ | %@",strDate,timeForRequest]

it shows me like this :יום שישי,19.08.2016 | 07: 00-16: 00

Observe the time is not correct, please help me to come out from this wired situation.

Thanks in advance.

Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98

2 Answers2

4

I'm pretty sure that the problem here is that the hebrew date in strDate is carrying unicode characters that make it display right-to-left. That's causing chaos when combined with the 'ordinary' left-to-right string in timeForResponse. The date formatter is picking that up from the hebrew locale.

Try this:

  1. Change your date format string to

[dateFormatter setDateFormat:@"dd.MM.yyyy,EEEE"];

  1. Change your string with format to

NSString *result = [NSString stringWithFormat:@"\u200E%@ | %@", timeForRequest, strDate];

The 0x200E unicode character is invisible but puts the rendering back into left-to-right mode.

After the above, this is the output that I'm getting:

07: 00-16: 00 | 17.08.2016,יום רביעי

ncke
  • 1,084
  • 9
  • 14
  • working with format but when i try to compare `07: 00-16: 00 | 17.08.2016,יום רביעי` with result it gave false result because of that hidden character – Prashant Tukadiya Aug 19 '16 at 05:38
  • Maybe you could remove the hidden first character ahead of any comparison: NSString *resultComp = result.length > 1 ? [result substringFromIndex:1] : result; Then compare against resultComp. – ncke Aug 19 '16 at 06:59
1

I just had to change from Debug to Release and Install the Release .exe, now both services are running and working without any problem