How to format DateTime for local locales in short format using MonoTouch

I tried several approaches, this is one of them:

System.Globalization.DateTimeFormatInfo format = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat;      
return dt.Value.ToString (format.ShortTimePattern);

The problem with this is that .NET 3.5 returns ".". as a time delimiter, which is most likely a mistake (since my Norwegian language uses a colon): .NET (3.5) formats time using periods, not colons, like TimeSeparator is an IT culture for it?

I also looked here: Getting current local time on iPhone?

But MT doesn't seem to have setTimeStyle on NSDateFormatter?

So who has any magic tricks up their sleeves?

My goal is to deduce:

9 p.m. / 9 a.m. PM

10: 09/10: 09 AM

like a status bar on an iPhone.

+5
2

:

var formatter = new NSDateFormatter ();
formatter.TimeStyle = NSDateFormatterStyle.Short;
Console.WriteLine (formatter.ToString (DateTime.Now));

, dot/colon ​​ Mono 2.12, , MonoTouch Mono 2.12 Mono 2.10 (, ), :

Console.WriteLine (DateTime.Now.ToString (new CultureInfo ("nb-NO").DateTimeFormat.ShortTimePattern));
+6

, ShortTimePattern TimeSeperator (, , ).

, iOS-only ( ) . :

using MonoTouch.Foundation;
    ...
    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        var d = DateTime.Now;
        Console.WriteLine("NSDate: " + GetCorrectTime(d));
    }
    ...
        // iOS-only (not cross-platform)
    public string GetCorrectTime (DateTime d)
    {
        var nsdate = DateTimeToNSDate(d);
        var nsdateformatter = new .NSDateFormatter();
        nsdateformatter.DateStyle = NSDateFormatterStyle.None;
        nsdateformatter.TimeStyle = NSDateFormatterStyle.Short;
        return nsdateformatter.ToString(nsdate);
    }
    ...
        // DateTime to NSDate was taken from [that post][2]
    public static NSDate DateTimeToNSDate(DateTime date)
    {
        return NSDate.FromTimeIntervalSinceReferenceDate((date-(new DateTime(2001,1,1,0,0,0))).TotalSeconds);
    }

:

NSDate: 17:40

, "nn-NO" ( ()).

+1

All Articles