我遇到了DateTime.ParseExtract问题。错误是String was not recognized as a valid DateTime
。C#将日期从字符串转换为日期格式
sqlserver 2012中的trialDate定义为folllow type = date,它以这种格式显示 MM/dd/yyyy。我猜这是sqlserver的默认值。我不知道如何将其更改为 dd/MM/yyyy或dd-MM-yyyy。
当我显示在ListView我这样做的日期(把口罩): '
下面是C#代码隐藏
string sTrialDate = "";
foreach (ListViewDataItem item in ListView1.Items)
{
CheckBox MyCheckBox = (CheckBox)item.FindControl("MyCheckBox");
if (MyCheckBox.Checked)
{
Label myTrialDate = (Label)item.FindControl("trialDatelbl");
sTrialDate = myTrialDate.Text;
}
}
问题是DATETIME.ParseExtract,这是我到目前为止所尝试的:
DateTime dt = DateTime.ParseExact("sTrialDate", "MM/dd/yyyy",
System.Globalization.CultureInfo.InvariantCulture); <=== not working
DateTime dt = DateTime.ParseExact("sTrialDate", "dd/MM/yyyy",
System.Globalization.CultureInfo.InvariantCulture); <=== not working
DateTime dt = DateTime.ParseExact("sTrialDate", "dd/MM/yyyy ",
System.Globalization.CultureInfo.InvariantCulture); <=== not working
DateTime dt = DateTime.ParseExact(Request.QueryString["sTrialDate"], "dd/MM/yyyy", null);
<==not working
'“sDateRdv”'看起来并不像一个日期我。 –
我改变了对不起,它应该sTrialDate – user3127986
'“sTrialDate”'也不像日期! –