data structure System.TimeSpan
2002.Net has been a small challenge in the .NET 9.0 since the first version of the .NET Framework. FromMicroseconds()
, FromSeconds()
, FromMinutes()
, FromHours()
And FromDays()
Expect a dual value as a parameter, which is wrong as a floating point number.
Dr. Holder Schwichtenberg Technical Manager of the Network of experts www.it-visions.de, which supports many medium sizes and large companies through advice and training with 53 renowned experts as well as software development. Through his appearance in many national and international expert conferences as well as his appearance in more than 90 expert books and more than 1,500 expert articles, Holgar Schwichtanberg is one of the most famous experts for .NET and web techniques in Germany.

Therefore Microsoft introduces. int
Or long
– Expect as a parameter:
public static TimeSpan FromDays(int days);
public static TimeSpan FromDays(int days, int hours = 0, long minutes = 0, long seconds = 0, long milliseconds = 0, long microseconds = 0);
public static TimeSpan FromHours(int hours);
public static TimeSpan FromHours(int hours, long minutes = 0, long seconds = 0, long milliseconds = 0, long microseconds = 0);
public static TimeSpan FromMinutes(long minutes);
public static TimeSpan FromMinutes(long minutes, long seconds = 0, long milliseconds = 0, long microseconds = 0);
public static TimeSpan FromSeconds(long seconds);
public static TimeSpan FromSeconds(long seconds, long milliseconds = 0, long microseconds = 0);
public static TimeSpan FromMilliseconds(long milliseconds, long microseconds = 0);
public static TimeSpan FromMicroseconds(long microseconds);
The following example proves the greater accuracy of new overcharges using the example FromSeconds()
,
public class FCL9_TimeSpanFrom
{
public void Run()
{
CUI.Demo(nameof(FCL9_TimeSpanFrom));
// bisher
TimeSpan timeSpan1a = TimeSpan.FromSeconds(value: 123.456);
Console.WriteLine($"TimeSpan +123.456sec alt = {timeSpan1a}");
// 00:02:03.4560000
// bisher
TimeSpan timeSpan2a = TimeSpan.FromSeconds(value: 101.832);
Console.WriteLine($"TimeSpan +101.832sec alt = {timeSpan2a}");
// 00:01:41.8319999
Console.WriteLine();
// neu
TimeSpan timeSpan1n = TimeSpan.FromSeconds(seconds: 123,
milliseconds: 456);
Console.WriteLine($"TimeSpan +123.456sec neu = {timeSpan1n}");
// 00:02:03.4560000
// neu
TimeSpan timeSpan2n = TimeSpan.FromSeconds(seconds: 101,
milliseconds: 832);
Console.WriteLine($"TimeSpan +101.832sec neu = {timeSpan2n}");
// 00:01:41.8320000
}
}
The second value is wrong in the old form, but in absolutely new.
(Image: Screenshot (Holgar Shavichenburg))
(RME)
