0
私は時間とともに2つの日付を減算したいと思います。結局、私は44日、14時間、15分のようなものを手に入れます。今、私は日付ピッカーと時刻ピッカーから日時減算uwp
をtakeing午前時間2時03分00秒(秒は、私は必要性をドント。)XAMLコード
日付と時刻のみを取得しています
<StackPanel HorizontalAlignment="Left">
<!--<TextBlock x:Name="textblock" Text="textblock"/>-->
<DatePicker x:Name="datepicker1" Margin="10"/>
<TimePicker x:Name="timepicker1" Margin="10"/>
<DatePicker x:Name="datepicker2" Margin="10"/>
<TimePicker x:Name="timepicker2" Margin="10"/>
<Button x:Name="datumbutton" Click="datumbutton_Click" Content="Combine"/>
<TextBlock x:Name="datumtextblock" Margin="20" Text="datum" />
<TextBlock x:Name="datumtextblock2" Text="datum2"/>
<TextBlock x:Name="vysledek" Text="vysledek"/>
</StackPanel>
UWPコード
using Windows.Globalization;
using Windows.Globalization.DateTimeFormatting;
private void datumbutton_Click(object sender, RoutedEventArgs e)
{
DateTimeFormatter dateFormatter = new DateTimeFormatter("shortdate");
DateTimeFormatter timeFormatter = new DateTimeFormatter("shorttime");
Calendar calendar = new Calendar();
calendar.ChangeClock("24HourClock");
DateTimeOffset selectedDate = this.datepicker1.Date;
DateTimeOffset combinedValue = new DateTimeOffset(new DateTime(selectedDate.Year, selectedDate.Month, selectedDate.Day) + this.timepicker1.Time);
DateTimeOffset selectedDate2 = this.datepicker2.Date;
DateTimeOffset combinedValue2 = new DateTimeOffset(new DateTime(selectedDate.Year, selectedDate.Month, selectedDate.Day) + this.timepicker2.Time);
calendar.SetDateTime(combinedValue);
calendar.SetDateTime(combinedValue2);
datumtextblock.Text= ("Combined value: " + dateFormatter.Format(combinedValue) + " " + timeFormatter.Format(combinedValue));
datumtextblock2.Text = ("Combined value: " + dateFormatter.Format(combinedValue2) + " " + timeFormatter.Format(combinedValue2));
System.TimeSpan odecet = combinedValue.Subtract(combinedValue2);
vysledek.Text = odecet.ToString();
}