Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 01.ObjectsAndClasses-Day of Week
- You are given a date in format day-month-year. Calculate and print the day of week in English.
- Examples
- Input Output
- 18-04-2016 Monday
- 27-11-1996 Wednesday
- Hints
- • Read the date as string from the Console.
- • Use the method DateTime.ParseExact(string date, format, provider) to convert the input string to object of type DateTime. Use format “d-M-yyyy” and CultureInfo.InvariantCulture.
- o Alternatively split the input by “-“ and you will get the day, month and year as numbers. Now you can create new DateTime(year, month, day).
- • The newly created DateTime object has a DayOfWeek property.
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _01DayOfWeek
- {
- class Program
- {
- static void Main(string[] args)
- {
- string dateAsString = Console.ReadLine();
- DateTime dateTime = DateTime.ParseExact(dateAsString, "dd-MM-yyyy", CultureInfo.InvariantCulture);
- Console.WriteLine(dateTime.DayOfWeek);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment