簡體   English   中英

日期時間“0001-01-01T00:00:00”的問題

[英]Problem with the DateTime "0001-01-01T00:00:00"

我的約會有問題。 我使用 postman 進行插入,無論我輸入什么,我總是返回“0001-01-01T00:00:00”。

還想將 output 限制在日期范圍內。

我非常感謝任何幫助

謝謝你

Model:

public class BusinessTripDocument
    {
        

        public long Id { get; set; }
        public string StartLocation { get; set; }
      [JsonPropertyName("startDateTime")]
        public DateTime StartDate { get; set; }
        public string Destination { get; set; }
        public DateTime DestinationDate { get; set; }
        public string Transportation { get; set; }
        public string SuperiorsApproval { get; set; }
// POST: api/Businesstripdocuments
       
        [HttpPost("new/{eId}")]
        public async Task<ActionResult<BusinessTripDocument>> PostBusinesstripdocuments(long eId, BusinessTripDocument businesstripdocuments)
        {
            Employee employee = await _context.Employees.FindAsync(eId);
            //  businesstripdocuments.Employee = employee;
            //   _context.Businesstripdocuments.Add(businesstripdocuments);
            employee.addDocument(businesstripdocuments);
            await _context.SaveChangesAsync();

            return CreatedAtAction("GetBusinesstripdocuments", new { id = businesstripdocuments.Id }, businesstripdocuments);
        }

Postman

僅從您顯示的代碼來看 - 在我看來,您應該只需要為您的 Model 提供DataType屬性?

//using System.ComponentModel.DataAnnotations;
public class BusinessTripDocument 
{
    ...
    [DataType(DataType.Date)]
    [JsonPropertyName("startDateTime")]
    public DateTime StartDate { get; set; }
    ...
}

我建議您可以采取兩種方式: 1.- 日期可以在 PostBusinesstripdocuments 方法中 2.- 日期可以是 class BusinessTripDocument 中的字符串,然后轉換為日期時間。

她就是例子: 在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM