안녕하세요, 올바르지 않은 날짜가보기에 있습니다.각도로 MM-dd-yyyy 형식으로 날짜를 표시하는 방법
다음은 일부 프로젝트 사진과 스냅 샷입니다.
모델 : -
public partial class Employee
{
public int Id { get; set; }
public string name { get; set; }
//[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
//[DataType(DataType.Date)]
public DateTime DOB { get; set; }
public string Gender { get; set; }
public string Email { get; set; }
public string Mobile { get; set; }
public string Address { get; set; }
public DateTime JoiningDate { get; set; }
public int DepartmentID { get; set; }
public int DesignationID { get; set; }
}
JSON 기능 데이터베이스에서 레코드를 LINQ를 사용하여 얻을 : -
public JsonResult getAll()
{
using (empEntities dataContext = new empEntities())
{
var employeeList = (from E in dataContext.Employees
join dep in dataContext.Departments on E.DepartmentID equals dep.Id
join dsg in dataContext.Designations on E.DesignationID equals dsg.Id
orderby E.Id
select new
{
E.Id,
E.name,
E.DOB,
E.Gender,
E.Email,
E.Mobile,
E.Address,
E.JoiningDate,
dep.DepartmentName,
E.DepartmentID,
dsg.DesignationName,
E.DesignationID
}).ToList();
var JsonResult = Json(employeeList, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = int.MaxValue;
return JsonResult;
}
}
보기 : -
<tr dir-paginate="employee in employees|orderBy:sortKey:reverse|filter:search|itemsPerPage:2">
@*<td style="width: 100px;">{{employee.DOB |date:'dd-MM-yyyy'}}</td>*@
<td style="width: 100px;">{{employee.DOB | date:"MM-dd-yyyy 'at' h:mma"}}</td>
각도 컨트롤러 : - 날짜 형식이 없기 때문에 정말 JSON에 존재한다
function GetAllEmployees() {
var getData = myService.getEmployees();
debugger;
getData.then(function (emp) {
//emp.DOB = new Date(emp.DOB);
$scope.employees = emp.data;
}, function (emp) {
alert("Records gathering failed!");
});
}
JSON의 규칙은 날짜에 ISO 8601 형식을 사용하는 것입니다. ASP.NET MVC는이 형식으로 날짜를 반환합니다. '/ Date (..)'는 어디에서 왔습니까? 어쨌든 * display * 형식을 변경하려면 문자열을 구문 분석 (예 :'new Date()') 한 다음 원하는 형식으로 배열해야합니다. –