DateTime.FromOADate() Method in C#
DateTime.FromOADate(Double) Method is used to return a DateTime equivalent to the specified OLE Automation Date.
Syntax: public static DateTime FromOADate (double d);
Here, it takes an OLE Automation Date value.Return Value: This method returns an object that represents the same date and time as d.
Exception: This method will give ArgumentException if the date is not a valid OLE Automation Date value.
Below programs illustrate the use of DateTime.FromOADate(Double) Method:
Example 1:
// C# program to demonstrate the // DateTime.FromOADate(Int64) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // converting 657435.0 OLE // Automation Date value. // into DateTime format // using FromOADate() method DateTime date2 = DateTime.FromOADate(657435.0); // Display the date2 System.Console.WriteLine("DateTime " + ": {0:y} {0:dd}",date2); } catch (ArgumentException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } |
DateTime : 3699 December 28
Example 2: For ArgumentException
// C# program to demonstrate the // DateTime.FromOADate(Int64) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // converting 657435.0 OLE // Automation Date value. // into DateTime format // using FromOADate() method DateTime date2 = DateTime.FromOADate(-657435.0); // Display the date2 System.Console.WriteLine("DateTime " + ": {0:y} {0:dd}",date2); } catch (ArgumentException e) { Console.WriteLine("The date is not a valid "+ "OLE Automation Date value."); Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } |
The date is not a valid OLE Automation Date value. Exception Thrown: System.ArgumentException
Reference:
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | Math.Tan() Method
- C# | Math.Cos() Method
- C# | Math.Sin() Method
- C# | CompareOrdinal() Method
- C# | Math.Exp() Method
- Queue.Contains() Method in C#
- C# | String.Contains() Method
- C# | Math.Abs() Method | Set - 1
- C# | IndexOfAny() Method
- C# | Math.Abs() Method | Set - 2
- TimeSpan.Add() Method in C#
- C# | StartsWith() Method
- C# | Uri.IsHexEncoding() Method
- Anonymous Method in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



