简体   繁体   English

返回DateTime.Now十进制

[英]Return DateTime.Now in decimals

How do I change the time from 60 minutes to 100 in an hour? 如何将时间从60分钟更改为一个小时内的100?

Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
      Device.BeginInvokeOnMainThread(() => LokaleTijdRange.Value = 
      float.Parse(DateTime.Now.ToString("HH.mm"), 
      CultureInfo.InvariantCulture.NumberFormat));
}

With this code, I'm getting normal times (but then with "." instead of ":") like 19:12 , 23:20 etc... However, is there a way to make it so that the time will be displayed in decimals of an hour? 有了这段代码,我得到了正常的时间(但是然后是19:12 : 19:12 : 23:20等,但是使用了“。”而不是“:”)……但是,有一种方法可以使时间变成以小时的小数显示? So that 20:30 gives 20.5 , and 20:45 will give 20.75 ? 这样20:3020.5 : 20:4520.75 I need this so I can count with times. 我需要这个,所以我可以数点时间。

您可以仅使用DateTime.Now.TimeOfDay.TotalHours

This will convert the time in DateTime into decimal value: 这会将DateTime中的时间转换为十进制值:

DateTime originalDT = Date.now();
float timeInDecimals = (float)originalDT.Hour + (float)(originalDT.Minute / 60.0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM