蓝冠官网-蓝冠公司|蓝冠招商注册-蓝冠开户
蓝冠官网(主管Q374919)

蓝冠官网jquery社区_使用jQuery DataTable套件,日期时间的资料要如何只显示日期就好?

练习使用jQuery DataTable套件,资料库内容是用北风资料库

目前是已经成功将资料取出且呈现在datatable了,但日期格式却想不出要怎么处理 @@

已经有试过ToString(“yyyy-MM-dd”)、format日期格式,但还是会把时间的部分呈现在画面上,请教各位要怎么修改Code的部分,才只会显示日期就好?

谢谢

程式码

Models

public class OrdersList
    {
        public List<Orders> OdList(string OrderID)
        {
            List<Orders> itemS = new List<Orders>();

            string sql = string.Format(@"Select * From Orders", OrderID);

            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[""].ConnectionString);

            try
            {
                conn.Open();
                SqlDataAdapter adpt = new SqlDataAdapter();
                using (SqlCommand cmd = new SqlCommand())
                {
                    DataTable ds = new DataTable();
                    cmd.Connection = conn;
                    cmd.CommandText = sql;
                    adpt.SelectCommand = cmd;
                    adpt.Fill(ds);

                    foreach (DataRow row in ds.Rows)
                    {
                        Orders item = new Orders();
                        
        item.OrderID = Int32.Parse(row["OrderID"].ToString());
        item.CustomerID = row["CustomerID"].ToString();
        item.EmployeeID = Int32.Parse(row["EmployeeID"].ToString());
        item.OrderDate = DateTime.Parse(row["OrderDate"].ToString());
        item.RequiredDate = DateTime.Parse(row["RequiredDate"].ToString());
        item.ShippedDate = DateTime.Parse(row["ShippedDate"].ToString());
        item.ShipVia = Int32.Parse(row["ShipVia"].ToString());
        item.Freight = decimal.Parse(row["Freight"].ToString());
        item.ShipName = row["ShipName"].ToString();
        item.ShipAddress = row["ShipAddress"].ToString();
        item.ShipCity = row["ShipCity"].ToString();
        item.ShipRegion = row["ShipRegion"].ToString();
        item.ShipPostalCode = row["ShipPostalCode"].ToString();
        item.ShipCountry = row["ShipCountry"].ToString();

                        itemS.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                var Error = ex.Message;
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }

            return itemS;
        }
    }

Controller

public ActionResult OrdersList()
        {
           
            return View();
        }
        [HttpPost]
        public string GetOrders(string OrderID)
        {
            using (NorthwindEntities db = new NorthwindEntities())
            {
                OrdersList con = new OrdersList();
                var result = con.OdList(OrderID);
                
                return JsonConvert.SerializeObject(result);
            }
        }

Views
View的部分就是使用jquery + ajax接后端资料

2023-01-09