Convert DateTime to a specified Format in C#



To Convert Datetime to  a specific format in C# we need to use ParseExtract.

According To Microsoft

ParseExact(String, String, IFormatProvider) Converts the specified string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.


Lets see How to use


     

var EventDates = Request.Form["EventDate"];


compEvent.EventDate = DateTime.ParseExact(EventDates, "dd/MM/yyyy", CultureInfo.InvariantCulture ).ToString("MM/dd/yyyy");
           
           




This will convert the Desired DateFormat.

No comments:

Post a Comment