可能重复:
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。两者都不起作用 –