I'm working on creating my own datetimepicker. I want to show the date as by the dateformat. The dateformat includes "MM-dd-yyyy" and other formats.
I wrote the code as below:
public DateTime getCurrentDate(string dateFormat)
{
curDate = DateTime.Now;
IFormatProvider theCultureInfo = new System.Globalization.CultureInfo("en-us", true);
return DateTime.ParseExact(curDate.ToShortDateString(), dateformat, theCultureInfo);
}
When I execute the program it shows: String was not recognized as a valid DateTime.
Provide me some solution to handle with error.