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
精彩评论