重複の可能性:
DateTime.ParseExact フォーマット文字列
文字列を DateTime オブジェクトに変換するにはどうすればよいですか?
例:
Sun Oct 07 2012 00:00:00 GMT+0500 (パキスタン標準時)
私はDateTime.Parse、Convert.TODateTimeなどを試しました。どれもうまくいきません。有効な DateTime 文字列ではないというエラーが表示されます。
jqueryからMVCコントローラーのアクションメソッドにdatetimeを送信する方法は次のとおりです。
$.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
}