I have a curious issue with the DatePicker View regarding DateTime Formats. My goal is to get the Date and Time starting at 00:00 (24 hours) format but I always get the Time as 12:00 AM (12 hours) format. That code is in the Xamarin.Forms PCL library:
<DatePicker x:Name="TruckAuftragBeginDatetime"
Format="dd.MM.yyyy"
TextColor="Aqua"
BackgroundColor="Black"
VerticalOptions="CenterAndExpand"
HorizontalOptions="EndAndExpand"
DateSelected="TruckAuftragBeginDatetimeOnDateSelected"></DatePicker>
I even tried to set Format as Format="dd.MM.yyyy HH:mm" with the same result in my DateSelected EventHandler. I always get something like that:
e.NewDate {11/30/2016 12:00:00 AM} Date: {System.DateTime} Day: 30 DayOfWeek: System.DayOfWeek.Wednesday DayOfYear: 335 Hour: 0 Kind: System.DateTimeKind.Unspecified Millisecond: 0 Minute: 0 Month: 11 Second: 0 Ticks: 636160608000000000 TimeOfDay: {System.TimeSpan} Year: 2016
sinceDateTime {11/30/2016 1:00:00 AM} Date: {System.DateTime} Day: 30 DayOfWeek: System.DayOfWeek.Wednesday DayOfYear: 335 Hour: 1 Kind: System.DateTimeKind.Local Millisecond: 0 Minute: 0 Month: 11 Second: 0 Ticks: 636160644000000000 TimeOfDay: {System.TimeSpan} Year: 2016
My Code (EventHandler):
private async void TruckAuftragBeginDatetimeOnDateSelected(object sender, DateChangedEventArgs e)
{
var sinceDateTime = e.NewDate.ToLocalTime();
}
As a temporary workaround I take the LocalTime which is one hour ahead in my timezone.
Question:
How can I get the datetime in 24 hour format with a result like:
e.NewDate {11/30/2016 00:00:00} Date: {System.DateTime} Day: 30 DayOfWeek: System.DayOfWeek.Wednesday DayOfYear: 335 Hour: 0 Kind: System.DateTimeKind.Unspecified Millisecond: 0 Minute: 0 Month: 11 Second: 0 Ticks: 636160608000000000 TimeOfDay: {System.TimeSpan} Year: 2016