Search code examples
xamarinxamarin.iosnsdateformatter

NSDateFormatter have extra dot in front of month for nb_NO (Norsk Bokmal) locale


I'm working in a Xamarin.IOs project. I'm trying to convert a DateTime object into the following format "dd. MMM yyyy" under "nb_NO" locale which should return something like, Ex: "05. feb 2018".

I'm using the following code snippets to achieve this, (C#)

var now = DateTime.Now;
var format = "dd. MMM yyyy";
var formatter = new NSDateFormatter { DateFormat = format, Locale = new NSLocale("nb_NO"), TimeZone = NSTimeZone.SystemTimeZone };
var nsDate = DateTimeToNSDate(now);
var formattedDate = formatter.StringFor(nsDate);

But what I get for formattedDate is something like Ex: "05. feb. 2018". There is an extra dot (period) after the month as well.

What can I do to get rid of this unexpected extra dot after the month in "nb_NO" locale?


Solution

  • After a long research, I tried the following string format, "dd. LLL yyyy".

    You have to use LLL instead of MMM to render the month.

    This just solved me the issue.

    You can find all the possible formats here!