C# Sharp Exercises: Long integer to valid time
C# Sharp DateTime: Exercise-22 with Solution
Write a C# Sharp program which shows that when a time that falls within this range is converted to a long integer value and is then restored and the original value is adjusted to become a valid time.
Sample Solution:-
C# Sharp Code:
using System;
public class Example22
{
public static void Main()
{
DateTime date1 = new DateTime(2016, 3, 14, 2, 30, 00);
Console.WriteLine("Invalid Time: {0}",
TimeZoneInfo.Local.IsInvalidTime(date1));
long ft = date1.ToFileTime();
DateTime date2 = DateTime.FromFileTime(ft);
Console.WriteLine("{0} -> {1}", date1, date2);
}
}
Sample Output:
Invalid Time: False 3/14/2016 2:30:00 AM -> 3/14/2016 2:30:00 AM
Flowchart :

C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to convert the specified string representation of a date and time to its DateTime equivalent using the specified array of formats, culture-specific format information, and style.
Next: Write a C# Sharp Program to convert the specified Windows file time to an equivalent UTC time.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Exercises: Weekly Top 12 Most Popular Topics
- Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools
- JavaScript: HTML Form Validation
- SQL Exercises, Practice, Solution - SUBQUERIES
- C Programming Exercises, Practice, Solution : For Loop
- Python Exercises, Practice, Solution
- Python Data Type: List - Exercises, Practice, Solution
- C++ Basic: Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - exercises on Employee Database
- SQL Exercises, Practice, Solution - exercises on Movie Database
- SQL Exercises, Practice, Solution - exercises on Soccer Database
- C Programming Exercises, Practice, Solution : Recursion