我有從數據庫數據生成xml的代碼。將字符串轉換爲正確的日期字符串
這裏是它
public HttpResponseMessage Index(DateTime today)
{
var timeTables = db.TimeTables
.Where(c=> c.Today == today)
.Select(c => new
{
c.INN,
c.StartDay,
c.StartPause,
c.EndPause,
c.EndDay
}).AsEnumerable();
var xdoc = new XDocument(
new XElement("data",
timeTables.Select(w =>
new XElement("worker",
new XAttribute("id", w.INN),
new XElement("start", w.StartDay),
new XElement("pause", w.StartPause),
new XElement("continue", w.EndPause),
new XElement("end", w.EndDay)
)
)
)
);
return new HttpResponseMessage() { Content = new StringContent(xdoc.ToString(), Encoding.UTF8, "application/xml") };
}
數據是從移動應用請求花費。移動應用程序發送c.StartDay例如像這樣17-8-2017T10:8:3
。在xml我需要顯示它這樣的yyyy-MM-ddTHH:mm:ss
我怎麼能這樣做的XML生成?
但'c.StartDay'還可以' 17-12-2017T10:45:55'?=! –
是的。你是對的@ MongZhu –
它必須記錄在'yyyy-MM-ddTHH:mm:ss' @MongZhu –