Convert DateTime to specific format

I am trying to convert this date format to “09/05/2018 14:30” a different format MMM-dd-yyyy HH:mm tt.

But I am getting the output as : Date in required format : May-09-2018 14:30:00 PM.
I need the output to be : Date in required format : May-09-2018 02:30:00 PM (need 02 instead of 14 in hour field)

The following are the steps which i did
converted to DateTime datttte-> DateTime.ParseExact("09/05/2018 14:30", "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture)

Converted to String in required format → datttte.ToString("MMM-dd-yyyy HH:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture)
Could you please help me,

1 Like

Hi @maria.josephina

Try this
DateTime.Now.ToString(“MMM-dd-yyyy hh:mm:ss tt”,System.Globalization.CultureInfo.InvariantCulture)

it will help you…

Thanks Regards

1 Like

Thanks @farhan.

DateTime.Now.ToString(“MMM-dd-yyyy hh:mm:ss tt” didnot work.
But DateTime.Now.ToString(“MMM-dd-yyyy h:mm:ss tt” worked by replacing “hh” with h.


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.