可能重複:
DateTime.ParseExact format string將字符串轉換(與UTC)爲DateTime
如何將字符串轉換爲DateTime對象?
例子:
太陽2012年10月7日00:00:00 GMT + 0500(巴基斯坦標準時間)
我都試過了,DateTime.Parse,Convert.TODateTime等無工作。我得到一個錯誤,它不是一個有效的DateTime字符串。
這裏是如何我從jQuery的發送日期時間到MVC控制器的操作方法:
$.ajax({
url: '@Url.Action("actionMethodName", "controllerName")',
type: "GET",
cache: false,
data: {
startDate: start.toLocaleString(),
endDate: end.toLocaleString()
},
success: function (data) {
}
});
我需要能夠獲得的日期時間回到控制器的操作方法:
public JsonResult actionMethodName(string startDate, string endDate)
{
if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
{
var start = DateTime.Parse(startDate); //Get exception here
var end = DateTime.Parse(endDate); //Get exception here
}
//Rest of the code
}
[你有什麼試過](http://whathaveyoutried.com)?你卡在哪裏?你還有幾個其他的例子? – Oded
DateTime.Parse/DateTime.TryParse –
@Zdeslav Vojkovic。兩者都不起作用 –