Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- class ThousandDaysAfterBirth
- {
- static void Main()
- {
- //Input must be in format dd-MM-yyyy (e.g 08-01-2017).
- string birthDate = Console.ReadLine();
- // Convert (parse) from string to DateTime (birthDate --> myDate).
- DateTime myDate = DateTime.ParseExact(birthDate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
- //Add 999 days to myDate.
- DateTime after1000 = myDate.AddDays(999);
- //Convert from DateTime to string and format it like this: dd-MM-yyyy
- string after1000ToString = after1000.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture);
- //Print 1000 days after birthDate.
- Console.WriteLine(after1000ToString);
- //*Not all cultures use the same format for dates. The "CultureInfo.InvariantCulture" property is neither a neutral nor a specific culture. It is a third type of culture that is culture-insensitive. The "CultureInfo.InvariantCulture" property is used if you are formatting a string (.ToString("dd-MM-yyyy")) or parsing a string (DateTime.Parse) that should be formattable / parseable by a piece of software independent of the user's local settings.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement