Advertisement
Guest User

1000DaysAfterBirth

a guest
May 20th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. class ThousandDaysAfterBirth
  5. {
  6. static void Main()
  7. {
  8. //Input must be in format dd-MM-yyyy (e.g 08-01-2017).
  9. string birthDate = Console.ReadLine();
  10.  
  11. // Convert (parse) from string to DateTime (birthDate --> myDate).
  12. DateTime myDate = DateTime.ParseExact(birthDate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  13.  
  14. //Add 999 days to myDate.
  15. DateTime after1000 = myDate.AddDays(999);
  16.  
  17. //Convert from DateTime to string and format it like this: dd-MM-yyyy
  18. string after1000ToString = after1000.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture);
  19.  
  20. //Print 1000 days after birthDate.
  21. Console.WriteLine(after1000ToString);
  22.  
  23. //*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.
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement