public override void WillActivate() { base.WillActivate(); var hour = DateTime.Now.Hour; var display = "zzzz"; if (hour < 6) { // zzz } else if (hour < 10) { display = "Breakfast time"; } else if (hour < 16) { display = "Lunch time"; } else if (hour < 21) { display = "Dinner time"; } else if (hour < 23) { display = "Bed time"; } var localizedDisplay = NSBundle.MainBundle.LocalizedString(display, comment: "greeting"); DisplayText.SetText(localizedDisplay); try { // "*****@*****.**" is located in the Watch Extension // multiple times: once for each language .lproj directory using (var image = UIImage.FromBundle("language")) { // DisplayImage.SetImage(image); } } catch (Exception ex) { DisplayText.SetText("Exception: " + ex.Message); } // easiest way to format date and/or time var localizedDateTime = NSDateFormatter.ToLocalizedString (NSDate.Now, NSDateFormatterStyle.Long, NSDateFormatterStyle.Short); DisplayTime.SetText(localizedDateTime); // long way of date or time formatting // var formatter = new NSDateFormatter (); // formatter.DateStyle = NSDateFormatterStyle.Medium; // formatter.TimeStyle = NSDateFormatterStyle.Long; // formatter.Locale = NSLocale.CurrentLocale; // var localizedDateTime = formatter.StringFor (NSDate.Now); }
public static bool Has24HourTimeFormat(this NSLocale locale) { var formatter = new NSDateFormatter(); formatter.Locale = locale; formatter.DateStyle = NSDateFormatterStyle.None; formatter.TimeStyle = NSDateFormatterStyle.Short; var dateString = NSDateFormatter.ToLocalizedString(DateTime.Now.ToNSDate(), NSDateFormatterStyle.None, NSDateFormatterStyle.Short); return(!dateString.Contains(formatter.AMSymbol) && !dateString.Contains(formatter.PMSymbol)); }
private static FileAttributeViewModel MakeModificationDateItem(NSFileAttributes attributes) { var modificationDate = attributes.ModificationDate; var keyLabel = NSBundle.MainBundle.LocalizedString("Modified", Empty); if (keyLabel == null) { return(null); } return(new FileAttributeViewModel(keyLabel, NSDateFormatter.ToLocalizedString(modificationDate, NSDateFormatterStyle.Medium, NSDateFormatterStyle.Medium))); }
internal void UpdateCell(Task task) { NameLabel.Text = task.Name; CattegoryLabel.Text = task.Cattegory; DatetimeLabel.Text = String.Format("{0} - {1} Hours", NSDateFormatter.ToLocalizedString(task.DateAndTime, NSDateFormatterStyle.Medium, NSDateFormatterStyle.Short), task.Duration); int reminder = DateTime.Compare(DateTime.Now, Extensions.NSDateToDateTime(task.DateAndTime)); if (0 <= reminder) { ReminderLabel.Text = "!!!"; } else { ReminderLabel.Text = ""; } }
public void ToLocalizedStringTest() { var str = NSDateFormatter.ToLocalizedString(NSDate.Now, NSDateFormatterStyle.Full, NSDateFormatterStyle.Full); Assert.IsNotNull(str); }