0

我将 ajax 日历控件用于文本框,已将其格式设置为"dd/mm/yyyy" .

  Bapur.Date = txtdate.Text;

在数据访问层

 cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = bapur.Date;

在保存时,就像上面一样(Date字符串Bapur是业务层类的对象)在数据库中,其中数据库中的数据表具有日期作为datetime格式。我得到一个错误:cant convert string to datetime当格式是我dint得到错误 "mm/dd/yyyy" .

基本上,我希望用户查看日期,dd/mm/yyyy但在保存时我想要它

mm/dd/yyyy

已经尝试了很多,但没有工作。

这是我的答案---- https://stackoverflow.com/a/11720162/1445836 -----

4

3 回答 3

2

您可以使用:

DateTime.ParseExact("yourDate","formatinWhichYouWant",culture of current string);

前任:

DateTime dt =DateTime.ParseExact("yourDate","formatinWhichYouWant",culture of current string);
于 2012-07-30T10:55:31.167 回答
0
string myDate = bapur.Text.Split("/");
string dateString = myDate[1] + "/" + myDate[0] + "/" + myDate[2];
于 2012-07-30T10:52:48.027 回答
0

得到了我的答案

            string old = txtdate.Text;
            string newDate = DateTime.ParseExact(old, "dd/MM/yyyy", null).ToString("MM/dd/yyyy");

            Bapur.Date = newDate.ToString();
于 2012-07-30T11:02:42.210 回答