2008-08-27 4 views
4

이 작업을 수행 할 때 나는 그것이 .NET 유형 JSON을 통해 제출 될 수 있도록 javascriptdate을 설정하려고하지만, 오전에 의해 직렬화되는, jQuery 전체에 date을 설정 string, .NET 유형으로 변환하려면 어떤 형식이 필요합니까? 나는이 (가) .NET 유형 바인딩을 수행하기 위해 서버에 MonoRail를 사용하고가 jQuery를

var regDate = student.RegistrationDate.getMonth() + "/" + student.RegistrationDate.getDate() + "/" + student.RegistrationDate.getFullYear(); 
j("#student_registrationdate").val(regDate); // value to serialize 

는, 그 옆으로 난 제대로 .NET 코드로 전송하려면 할 수있는 형태의 숨겨진 필드 값을 설정하는 것을 알 필요가있다.

답변

2

MSDN article에는 몇 가지 예가 있습니다. 구문 분석 할 수있는 날짜 문자열은 찾고자하는 것입니까? 트래비스에서 알 수 있듯이

string dateString = "5/1/2008 8:30:52 AM"; 
DateTime date1 = DateTime.Parse(dateString, CultureInfo.InvariantCulture); 
2

, 당신은 단순히 문자열로 (다시 전달하는 내용에 따라) 매개 변수 또는 클래스 속성을 변경할 수는 자신의 예로서 구문 분석.

this article을 살펴볼 수도 있습니다. 이는 DateTime JSON 직렬화에 대한 직접 변환이 ticks 속성과 비슷한 것을 사용함을 제안합니다.

1

명료하고 읽기 쉽도록 최상의 조합을 제공하는 YYYY-MM-DD 표기법을 사용하는 것이 좋습니다.

너무 :

var regDate = student.RegistrationDate.getFullYear() + "-" + student.RegistrationDate.getMonth() + "-" + student.RegistrationDate.getDate(); j("#student_registrationdate").val(regDate);