开发者

String to Datetime conversion

开发者 https://www.devze.com 2023-03-03 21:55 出处:网络
When I enter the value 25.12.2011, this error appears: System.Web.Services.Protocols.SoapException: Server was unable to process开发者_C百科 request.

When I enter the value 25.12.2011, this error appears:

System.Web.Services.Protocols.SoapException: Server was unable to process开发者_C百科 request. 
   ---> System.InvalidCastException: Conversion from string to type 'Date' is not valid.


It's probably expecting the date in a different format, such as yyyy-mm-dd or (assuming american formatting) mm/dd/yyyy.


you can do TryParseExact()

 if (DateTime.TryParseExact("25.12.2011", "dd.mm.yyyy", CultureInfo.CurrentCulture,
                                DateTimeStyles.None, out dateValue))
{
   string s = Convert.ToString(dateValue);
}

If you want to format to particular format see String.Format

0

精彩评论

暂无评论...
验证码 换一张
取 消