I’m working on a custom date format converter and everything seems to work fine until I get an hour > 11. Currently we’re using 24-hour format but I get the same behavior when I revert to 12 hr format using the long time converter. As as the hour reaches noon it formats 12 hrs behind.
public static string DateFormatConverter(string date)
{
DateTime result = DateTime.ParseExact(date, "yyyyMMddhhmmss", null);
string month = result.ToLongDateString().Replace(DateTime.Now.DayOfWeek + ",", "");
month = month.Replace(DateTime.Now.Year.ToString(), "");
month = month.Replace(DateTime.Now.Day.ToString() + ",", "");
date = result.Day.ToString() + " " + month + result.ToString("yy") + " " + result.ToString("HH:mm:ss");
date = date.Replace(" ", " ");
return date;
}
Here is the input:
1)20230629105843
2)20230629124942
Here is the output:
1)29 June 23 10:58:43
2)29 June 23 00:49:42
>Solution :
See the docs, hh is for 12 hour format, you need HH for 24 hour format