C# Sharp Programming Exercises

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}", 
      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 :

Flowchart: C# Sharp Exercises - Long integer to valid time

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?

New Content: Composer: Dependency manager for PHP, R Programming