- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
TimeSpan.FromDays() Method in C#
The TimeSpan.FromDays() method in C# is used to return a TimeSpan that represents a specified number of days, where the specification is accurate to the nearest millisecond.
Syntax
The syntax is as follows −
public static TimeSpan FromDays (double val);
Above, the parameter val is the number of days, accurate to the nearest millisecond.
Example
Let us now see an example −
using System; public class Demo { public static void Main(){ TimeSpan span1 = new TimeSpan(5, 25, 0); TimeSpan span2 = new TimeSpan(1, 10, 0); TimeSpan span3 = TimeSpan.FromDays(43.999999); Console.WriteLine("TimeSpan1 = "+span1); Console.WriteLine("TimeSpan2 = "+span2); Console.WriteLine("TimeSpan3 = "+span3); Console.WriteLine("Result (Comparison of span1 and span2) = "+TimeSpan.Compare(span1, span2)); } }
Output
This will produce the following output −
TimeSpan1 = 05:25:00 TimeSpan2 = 01:10:00 TimeSpan3 = 43.23:59:59.9140000 Result (Comparison of span1 and span2) = 1
Example
Let us now see another example −
using System; public class Demo { public static void Main(){ TimeSpan span1 = new TimeSpan(-3, 15, 0); TimeSpan span2 = new TimeSpan(-2, 05, 10); TimeSpan span3 = TimeSpan.FromDays(0.000323456); Console.WriteLine("TimeSpan1 = "+span1); Console.WriteLine("TimeSpan2 = "+span2); Console.WriteLine("TimeSpan3 = "+span3); Console.WriteLine("Result (Comparison of span1 and span2) = "+TimeSpan.Compare(span1, span2)); Console.WriteLine("Result (Comparison of span2 and span3) = "+TimeSpan.Compare(span2, span3)); } }
Output
This will produce the following output −
TimeSpan1 = -02:45:00 TimeSpan2 = -01:54:50 TimeSpan3 = 00:00:27.9470000 Result (Comparison of span1 and span2) = -1 Result (Comparison of span2 and span3) = -1
Advertisements