using System.Collections.Generic;
using System.Globalization;
namespace ConsoleApplication2
public static void Main(string[] args)
Console.WriteLine(Convert.ToDateTime("2018/04/13"));
string inputDate = Console.ReadLine();
DateTime convertedDate = DateTime.Parse(inputDate, CultureInfo.CurrentCulture);
DateTime convertedExact = DateTime.ParseExact(inputDate, "dd mm yyyy", null);
DateTime convertedTryExact;
if (DateTime.TryParseExact(inputDate, "dd mm yyyy", null, DateTimeStyles.None, out convertedTryExact))
Console.WriteLine(convertedTryExact);
Console.WriteLine("Invalid date format");
private static void BasicDate()
DateTime currentDateTime = DateTime.Now;
Console.WriteLine(DateTime.Now);
Console.WriteLine(currentDateTime.ToShortDateString());
Console.WriteLine(currentDateTime.ToShortTimeString());
Console.WriteLine(currentDateTime.ToLongDateString());
Console.WriteLine(currentDateTime.ToLongTimeString());
Console.WriteLine(currentDateTime.ToString("MMMM dd, yyyy"));
DateTime oldDate = new DateTime(2018, 4, 12);
Console.WriteLine(DateTime.IsLeapYear(2016));
TimeSpan duration = currentDateTime - oldDate;
TimeSpan newTimeDuration = new TimeSpan(1, 2, 30, 0);
Console.WriteLine(DateTime.Now.AddDays(1));
Console.WriteLine(DateTime.Now.AddHours(1));
Console.WriteLine(DateTime.Now.Add(newTimeDuration));