Question

Screenshot from https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/ApiExamples DateTime Example.

Although both dates match, the picker does not. I've tried both setting the timezone on the picker and trying to implement a value converter without success.

public class DateConverter : MvxValueConverter<NSDate, DateTime>
{
    protected override DateTime Convert(NSDate date, Type targetType, object parameter, CultureInfo culture)
    {
        return (new DateTime(2001, 1, 1, 0, 0, 0)).AddSeconds(date.SecondsSinceReferenceDate);
    }
    protected override NSDate ConvertBack(DateTime date, Type targetType, object parameter, CultureInfo culture)
    {
        return NSDate.FromTimeIntervalSinceReferenceDate((date - (new DateTime(2001, 1, 1, 0, 0, 0))).TotalSeconds);
    }
}

enter image description here

Was it helpful?

Solution

For anyone who finds this, issue is UIDatePicker does not respect setting TimeZone or Locale, hence everything returned or set to it is expected to be in UTC.

MvvmCross was patched to take this into account

https://github.com/MvvmCross/MvvmCross/pull/662

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top