Advertisement
Ivo123

Untitled

Aug 18th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. /*Write a program that reads a date and time given in the format: day.month.year hour:minute:second and prints the date and time
  2.  after 6 hours and 30 minutes (in the same format) along with the day of week in Bulgarian.*/
  3. using System;
  4. using System.Globalization;
  5.  
  6. class PrintingTheTimeAfterAWhile
  7. {
  8.     static void Main()
  9.     {
  10.         try
  11.         {
  12.             Console.Write("Enter the date and time in the format [d.MM.yyyy HH:mm:ss]: ");
  13.             string enteringDate = Console.ReadLine();
  14.  
  15.             DateTime date = DateTime.ParseExact(enteringDate, "d.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture);
  16.  
  17.             DateTime newDate = date.AddHours(6.5);
  18.  
  19.             Console.WriteLine("Your date: {0} - {1}", enteringDate, date.DayOfWeek);
  20.             Console.WriteLine("Your date after 6 hours and 30 minutes: {0} - {1}", newDate, newDate.DayOfWeek);
  21.         }
  22.         catch (FormatException)
  23.         {
  24.             Console.WriteLine("Invalid format");
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement