我如何获取datetime值,因为我认为这里的问题是存储库值是字符串而不是日期值
Begins with
它应该是equal
代码:
RepositoryItemComboBox repositoryItemComboBox1 = new RepositoryItemComboBox();
ci.DateTimeFormat.FullDateTimePattern = "dd MMM yyyy HH:mm:ss tt";
private void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
GridView view = sender as GridView;
for (int i = 0; i < gridView1.RowCount; i++)
{
if (gridView1.GetDataRow(i) == null)
{
break;
}
DateTime signIn1 = Convert.ToDateTime(gridView1.GetDataRow(i)["signIn"]);
DateTime signIn_md = Convert.ToDateTime(signIn1.ToString(ci.DateTimeFormat.FullDateTimePattern));
if (!repositoryItemComboBox1.Items.Contains(signIn_md))
{
repositoryItemComboBox1.Items.Add(signIn_md);
}
}
if (e.Column.FieldName == "signIn" && view.IsFilterRow(e.RowHandle))
{
e.RepositoryItem = repositoryItemComboBox1;
repositoryItemComboBox1.Sorted = true;
}
}
private void filterControl1_BeforeShowValueEditor(object sender, DevExpress.XtraEditors.Filtering.ShowValueEditorEventArgs e)
{
if (e.CurrentNode.Property.Name == "signIn")
{
e.CustomRepositoryItem = repositoryItemComboBox9;
}
}
答案 0 :(得分:0)
如果我理解正确,您希望将字符串转换为DateTime。
string strDate = "01 Aug 2016 15:31:07 PM";
DateTime dateTime = Convert.ToDateTime(strDate);
答案 1 :(得分:0)
为什么要将输入转换为DateTime
两次?显然这里有一些错误:
DateTime signIn1 = Convert.ToDateTime(gridView1.GetDataRow(i)["signIn"]);
DateTime signIn_md = Convert.ToDateTime(signIn1.ToString(ci.DateTimeFormat.FullDateTimePattern));
也许您应该使用DateTime.ParseExact
?既然您知道所需格式到底是什么,您可以用以下内容替换它:
DateTime signIn_md = DateTime.ParseExact(gridView1.GetDataRow(i)["signIn"], new String[] { "dd MMM yyyy HH:mm:ss tt" }, new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.None);