grach

TimeOfExam_StartUpTime

Feb 1st, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TimeOfExam
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.  
  13.         {
  14.             Console.Write("Exam start at: ");
  15.             Console.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
  16.                 //Console.WriteLine("Enter FIRST time: for example:hour: min:sec 15:25:10");
  17.                 //DateTime firstTime = DateTime.Now.ToString("h:mm:ss tt");
  18. DateTime firstTime = new DateTime();
  19.             firstTime = DateTime.Parse(DateTime.Now.ToString("h:mm:ss tt"));
  20.             //firstTime = DateTime.Parse(Console.ReadLine());
  21.  
  22.             Console.WriteLine("Enter LAST time: for example:hour:  min:sec 15:25:10");
  23.             DateTime secondTime = new DateTime();
  24.             secondTime = DateTime.Parse(Console.ReadLine());
  25.  
  26.  
  27.             if (secondTime < firstTime)
  28.             {
  29.                 TimeSpan difference = (firstTime - secondTime);
  30.                 difference -= TimeSpan.FromHours(24);
  31.                 difference = difference.Duration();
  32.                 Console.WriteLine("Time of Exam: {0}", difference);
  33.  
  34.  
  35.             }
  36.             else if (secondTime > firstTime)
  37.             {
  38.                 TimeSpan difference = (secondTime - firstTime);
  39.                 Console.WriteLine("Time of Exam: {0}", difference);
  40.  
  41.             }
  42.             Console.ReadLine();
  43.  
  44.         }
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment