C# में TimeSpan.FromMilliseconds() विधि का उपयोग एक TimeSpan को वापस करने के लिए किया जाता है जो एक निर्दिष्ट संख्या में मिलीसेकंड का प्रतिनिधित्व करता है।
वाक्य रचना इस प्रकार है -
सिंटैक्स
public static TimeSpan FromMilliseconds (double val);
ऊपर, वैल मिलीसेकंड की संख्या है।
उदाहरण
आइए अब एक उदाहरण देखें -
using System; public class Demo { public static void Main() { TimeSpan span1 = TimeSpan.FromDays(15); TimeSpan span2 = new TimeSpan(5, 15, 30); TimeSpan span3 = TimeSpan.FromHours(5); TimeSpan span4 = TimeSpan.FromMilliseconds(876876876.1); Console.WriteLine("TimeSpan1 = "+span1); Console.WriteLine("TimeSpan2 = "+span2); Console.WriteLine("TimeSpan3 = "+span3); Console.WriteLine("TimeSpan4 = "+span4); Console.WriteLine("Result (Comparison of span1 and span2) = "+TimeSpan.Compare(span1, span2)); Console.WriteLine("Result (Comparison of span2 and span3) = "+TimeSpan.Compare(span2, span3)); Console.WriteLine("Result (Comparison of span1 and span3) = "+TimeSpan.Compare(span1, span3)); Console.WriteLine("Result (Comparison of span3 and span4) = "+TimeSpan.Compare(span3, span4)); } }
आउटपुट
यह निम्नलिखित आउटपुट देगा -
TimeSpan1 = 15.00:00:00 TimeSpan2 = 05:15:30 TimeSpan3 = 05:00:00 TimeSpan4 = 10.03:34:36.8760000 Result (Comparison of span1 and span2) = 1 Result (Comparison of span2 and span3) = 1 Result (Comparison of span1 and span3) = 1 Result (Comparison of span3 and span4) = -1
उदाहरण
आइए अब एक और उदाहरण देखें -
using System; public class Demo { public static void Main() { TimeSpan span1 = TimeSpan.FromHours(0.78787); TimeSpan span2 = new TimeSpan(10, 30, 40); TimeSpan span3 = TimeSpan.FromHours(5); TimeSpan span4 = TimeSpan.FromMilliseconds(1); Console.WriteLine("TimeSpan1 = "+span1); Console.WriteLine("TimeSpan2 = "+span2); Console.WriteLine("TimeSpan3 = "+span3); Console.WriteLine("TimeSpan4 = "+span4); Console.WriteLine("Result (Comparison of span1 and span2) = "+TimeSpan.Compare(span1, span2)); Console.WriteLine("Result (Comparison of span2 and span3) = "+TimeSpan.Compare(span2, span3)); Console.WriteLine("Result (Comparison of span1 and span3) = "+TimeSpan.Compare(span1, span3)); Console.WriteLine("Result (Comparison of span3 and span4) = "+TimeSpan.Compare(span3, span4)); } }
आउटपुट
यह निम्नलिखित आउटपुट देगा -
TimeSpan1 = 00:47:16.3320000 TimeSpan2 = 10:30:40 TimeSpan3 = 05:00:00 TimeSpan4 = 00:00:00.0010000 Result (Comparison of span1 and span2) = -1 Result (Comparison of span2 and span3) = 1 Result (Comparison of span1 and span3) = -1 Result (Comparison of span3 and span4) = 1