Right, after a bit of digging, I've managed to get a solution that works.
Even though my question was originally about ar-SA, it does apply to any right-to-left culture.
I ended up using unicode characters to explicitly state what parts of the string were left-to-right and right-to-left.
So, using the constants -
private const char LeftToRightCharacter = (char)0x200E;
private const char RightToLeftCharacter = (char)0x200F;
I can then build up a string of the date as follows -
if (culture.TextInfo.IsRightToLeft)
{
return
LeftToRightCharacter +
date.ToString("yyyy-", culture) +
RightToLeftCharacter +
date.ToString("MMM", culture) +
LeftToRightCharacter +
date.ToString("-dd", culture);
}
return date.ToString("dd-MMM-yyyy", culture);
...where culture is a CultureInfo (with the DateTimeFormat.Calendar set to new GregorianCalendar()) and date is a DateTime.
So, for the date 06-Jun-2017, in en-GB I get -
06-Jun-2017
and in ar-SA I get -
2017-يونيو-06
Now that I've got that as a string, I can add the time on either side (to the left, if the culture is RTL and on the right if the culture is LTR).
It was useful seeing how Unicode deals with these characters, along with the other characters I could have used instead - http://www.unicode.org/reports/tr9/
ar-SA
, the day should be11
and the year1438
. By default it uses theUmAlQuaraCalendar
, not theGregorianCalendar
. Did you alter the culture in some way? Please show that here so we can reproduce the problem. (But yes, I see that the Arabic text is pushed to the right withMMM
. Looking into that still.) – Matt Johnson-Pint