我有以下有效的代码:
<%@ WebService Language="C#" Class="Absences" %>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Script;
using System.Web.Script.Services;
using System.Web.Services;
public class Absence
{
public string name;
public DateTime from;
public DateTime to;
public Absence(string m_name, DateTime m_from, DateTime m_to)
{
name = m_name;
from = m_from;
to = m_to;
}
public Absence() { }
}
[ScriptService]
public class Absences : WebService {
List<Absence> Absence = new List<Absence>();
SqlConnection connection;
SqlCommand command;
SqlDataReader reader;
[WebMethod()]
public List<Absence> GetAbsences(string strDateYear, string strDateMonth, string strDateDay)
{
var absences = new List<Absence>();
using (connection = new SqlConnection(ConfigurationManager.AppSettings["connString"]))
{
using (command = new SqlCommand(@"select full_name, from_date, to_date from table1", connection))
{
connection.Open();
using (reader = command.ExecuteReader())
{
int NameIndex = reader.GetOrdinal("full_name");
int FromIndex = reader.GetOrdinal("from_date");
int ToIndex = reader.GetOrdinal("to_date");
while (reader.Read())
{
absences.Add(new Absence(reader.GetString(NameIndex), reader.GetDateTime(FromIndex), reader.GetDateTime(ToIndex)));
}
}
}
}
return absences;
}
}
唯一的问题是日期,它们在 JSON 数据中以一种奇怪的格式出现,例如:
"from":"\/Date(1353456000000)\/"
我怎样才能得到以下格式的日期dd/mm/yy
?