Advertisement
aslv

Beer Time

Mar 23rd, 2014
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. namespace BeerTime
  5. {
  6.     class Beer
  7.     {
  8.         static void Main()
  9.         {
  10.             DateTime morning = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 3, 0, 0);
  11.             DateTime afternoon = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 13, 0, 0);
  12.             DateTime current;
  13.             if (DateTime.TryParseExact(Console.ReadLine(), "h:mm tt", new CultureInfo("en-US"), DateTimeStyles.None, out current))
  14.             {
  15.                 if (current < morning || current >= afternoon)
  16.                 {
  17.                     Console.WriteLine("beer time");
  18.                 }
  19.                 else
  20.                 {
  21.                     Console.WriteLine("non-beer time");
  22.                 }
  23.             }
  24.             else
  25.             {
  26.                 Console.WriteLine("invalid time");
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement