The whole idea to work with strings representing data instead of data itself is utterly bad, counter-productive, but presently is a very typical behavior of poor developers. Don't go this way. Do everything with the type
System.DateTime
, not with the string. The string can only be on output and never on input. (Yes, serializers use strings, but they should use some fixed culture-neutral "round-trip" string representation, preferably UCT
This type has a number of
ToString
method with the culture parameters parameters (implementing
IFormatProvider>
) and/or string parameters representing format explicitly:
https://msdn.microsoft.com/en-us/library/system.datetime.tostring%28v=vs.110%29.aspx[
^].
For format, please see:
https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx[
^],
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[
^].
In rare cases when you have string representing time on input (you have to make sure they are really rare), you can use some of the methods
Parse
,
ParseExact
,
TryParse
or
TryParseExact
:
https://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx[
^].
—SA