I want to convert 'yy/MM/dd HH:mm:ss' format like 17/07/18 06:30:20 to Jul.18, 2017 06:30:20 in c#. What is the best way to do that?
Asked
Active
Viewed 126 times
-4
-
Pick one or build your own: https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.80).aspx – mxmissile Jul 18 '17 at 17:45
-
@mxmissile MS have a new one, i think it is a better one - https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings – Bakudan Jul 18 '17 at 17:46
-
Are you starting with a `string` or a `DateTime`? `DateTime` does not _have_ a format, it only gets one when you _display_ it, so it's not clear from the question what you're starting with (and the answer will be different) – D Stanley Jul 18 '17 at 17:49
-
Sorry for the bad title but the answer given by Aman worked for me. Thanks to all. – Fresher coder Jul 18 '17 at 17:55
1 Answers
1
You can use DateTime.ParseExact
as shown below:
DateTime.ParseExact("17/07/18 06:30:20", "yy/MM/dd HH:mm:ss",
CultureInfo.InvariantCulture
).ToString("MMM. dd, yyyy HH:mm:ss");

Aman Sahni
- 212
- 1
- 8