C# 如何在xamarin表单日期选择器中使用当前日期时间?
我有一个xamarin应用程序正在申请休假。学生应在休假之日起3天内申请休假。如果他们在2020年10月3日休假,则应在10月6日或之前申请休假。我使用日历选择日期,并将最大日期设置为今天,最小日期设置为今天-3。因此,最后剩下的几天将不可用。它起作用了。但是当学生手动将设备日期设置为任何过去的日期时。然后应用程序中的日历也更改为该日期。如何预防这种情况C# 如何在xamarin表单日期选择器中使用当前日期时间?,c#,xamarin.forms,datepicker,C#,Xamarin.forms,Datepicker,我有一个xamarin应用程序正在申请休假。学生应在休假之日起3天内申请休假。如果他们在2020年10月3日休假,则应在10月6日或之前申请休假。我使用日历选择日期,并将最大日期设置为今天,最小日期设置为今天-3。因此,最后剩下的几天将不可用。它起作用了。但是当学生手动将设备日期设置为任何过去的日期时。然后应用程序中的日历也更改为该日期。如何预防这种情况 请在这方面帮助我这里有一个小样本,可以从互联网上获取日期,而不依赖于您的本地机器 视图: <StackLayout> <
请在这方面帮助我这里有一个小样本,可以从互联网上获取日期,而不依赖于您的本地机器 视图:
<StackLayout>
<Label x:Name="dateLabel" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
<Button Text="Get Date" Clicked="Button_Clicked" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</StackLayout>
关于明文HTTP问题的一点补充说明:
您需要对照一些外部时间源进行检查-提交数据时,时间服务器或您自己的服务器需要验证数据
private void Button_Clicked(object sender, EventArgs e)
{
using (var httpClient = new HttpClient())
{
var response = httpClient.GetStringAsync(new Uri("http://worldtimeapi.org/api/timezone/Asia/Kolkata")).Result;
ServerDateTime sDateTime = Newtonsoft.Json.JsonConvert.DeserializeObject<ServerDateTime>(response);
dateLabel.Text = sDateTime.datetime.ToString("dd.MM.yyyy");
}
}
public class ServerDateTime
{
public string abbreviation { get; set; }
public string client_ip { get; set; }
public DateTime datetime { get; set; }
public int day_of_week { get; set; }
public int day_of_year { get; set; }
public bool dst { get; set; }
public object dst_from { get; set; }
public int dst_offset { get; set; }
public object dst_until { get; set; }
public int raw_offset { get; set; }
public string timezone { get; set; }
public int unixtime { get; set; }
public DateTime utc_datetime { get; set; }
public string utc_offset { get; set; }
public int week_number { get; set; }
}