gpt4 book ai didi

c# - 如何在 javascript 中显示 C# 的日期时间?

转载 作者:行者123 更新时间:2023-11-28 13:37:51 25 4
gpt4 key购买 nike

我有课

http://pastebin.com/z5JVWCms

 public string Tankerler()
{
DataTable dt = new DataTable();

using (SqlConnection con = new SqlConnection("Data Source=local;Initial Catalog=DB;User ID=se;Password=1"))
{
using (

SqlCommand cmd = new SqlCommand("select OrderDate=Siparisler.DateScheduled,uruncikistarih=UrunTransfer.DateRealized,Siparis_Veren_Firma=Bayi.FirmName,plate=UrunTransfer.Plate,Driver=Surucu.Name,lat=TankerKonum.Lat,lng=TankerKonum.Lng,Speed=TankerKonum.Speed,Zaman=TankerKonum.ReadTime,IrsaliyeNo=UrunTransfer.PrintOutID from ProductTransfer as UrunTransfer join TransferOrder as Siparisler on Siparisler.OID=UrunTransfer.TransferOrderID Join Dealer as Bayi on Bayi.OID=Siparisler.DealerID Join Driver as Surucu on Surucu.OID=Siparisler.DriverID join devcocom_admin.TankerLocation as TankerKonum on TankerKonum.TankerID=Siparisler.TankerID where UrunTransfer.DateRealized >DATEADD(HOUR, - 24, GETDATE()) and TankerKonum.OID in (Select MAX(TankerKonum.OID) from devcocom_admin.TankerLocation as TankerKonum group by TankerKonum.TankerID)", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
return serializer.Serialize(rows);
}
}

}

我通过这个类从数据库中获取一些字段。

我的 JavaScript 代码

http://pastebin.com/EpPb9Yr3

    var markers2 = JSON.parse('<%=Tankerler() %>');


for (i = 0; i < markers2.length; i++) {

var data2 = markers2[i]

title: "Plate:" + " " + " " + data2.plate+ "\n" + "Speed:" +

" " + data2.speed+ " " + "h/km" + "\n" + "Driver: " + " " + data2.Drvier+ "\n" +

"Print OUT ID :" + " " + data2.prntID+" "+"OrderDate: "+data2.ordDate,

}

结果是这样的:

车牌:34AAA34 速度:120 小时/公里 司机:John 打印输出 ID:ABC12345 订单日期:/日期(138472560000)/

但是在sql OrderDate中:2013-11-20 21:24:10.000

最佳答案

您正在使用 JavaScriptSerializer ,这就是它序列化日期的方式。如果您想将它们序列化为不同的格式,您可以尝试其他序列化程序,例如 Json.NET .

来自他们的网站:

Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Sizes = new string[] { "Small" };

string json = JsonConvert.SerializeObject(product);
//{
// "Name": "Apple",
// "Expiry": "2008-12-28T00:00:00",
// "Sizes": [
// "Small"
// ]
//}

关于c# - 如何在 javascript 中显示 C# 的日期时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20115598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com