string to DateTime conversion in C#

后端 未结 5 1245
陌清茗
陌清茗 2020-12-20 18:11

Stupid questions but cant get my head around it... I have a string in this format 20081119

And I have a C# method that converts the string to a DateTime to be entere

5条回答
  •  攒了一身酷
    2020-12-20 18:20

    Date Time is a class that, by default, formats it's ToString as 19/11/2008 12:00:00 AM

    This is from MSDN which may help you

    Because the appearance of date and time values is dependent on such factors as culture, international standards, application requirements, and personal preference, the DateTime structure offers a great deal of flexibility in formatting date and time values through the overloads of its ToString method. The default DateTime.ToString() method returns the string representation of a date and time value using the current culture's short date and long time pattern. The following example uses the default DateTime.ToString() method to display the date and time using the short date and long time pattern for the en-US culture, the current culture on the computer on which the example was run.

    You may be able, therefore, to overload the ToString on DateTime to the desired format, else pass the string representation directly to the stored procedure instead

提交回复
热议问题