Convert DateTime to a specified Format
Use DateTime.ParseExact
, e.g.:
DateTime.ParseExact("12/02/21 10:56:09", "yy/MM/dd HH:mm:ss",
CultureInfo.InvariantCulture
).ToString("MMM. dd, yyyy HH:mm:ss")
Even easier way to convert Date:
Convert.ToDateTime("12/02/21 10:56:09").ToString("MMM.dd,yyyy HH:mm:ss");
var dateTime = DateTime.ParseExact("12/02/21 10:56:09", "yy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
var text = dateTime.ToString("MMM. dd, yyyy HH:mm:ss");