簡體   English   中英

為什么像 dd-MMM-yyyy 這樣的存儲日期會被轉換為 dd-MM-yyyy?

[英]Why storing the date like dd-MMM-yyyy is getting converted to dd-MM-yyyy?

我有一個非常不同的問題。

我已將我的 mvc 應用程序部署到實時服務器。

它具有像這樣的“01/07/2019”這樣的日期時間格式。

我有一個從 jquery datetimepicker 填充的文本框。 它像這樣填充 27/Jul/2019 但在 sql 表中它像2019-07-17 00:00:00.000一樣存儲,並且在將數據從數據庫綁定到 textboxfor 之后,它看起來像這樣 27-07-2019。

保存后,它會為所有大於 12 的日期拋出錯誤,例如13/07/2019但對於 13/Jul/2019,它運行良好。

如何解決這個問題?

@Html.EditorFor(model => model.InspectionReport.InspectionDate, new { htmlAttributes = new { @class = "form-control  input-sm pull-right text-box single-line" } })

查詢:

$("#InspectionReport_InspectionDate").datepicker({ dateFormat: 'dd/M/yy' });

班級:

[Required]
[Display(Name = "Inspection Date")]
[DisplayFormat(DataFormatString = "{0: dd-MMM-yyyy}")]
public DateTime InspectionDate { get; set; }

DateTime(2)數據類型的日期字段中,日期值存儲為沒有格式的值。

因此,要顯示該值,請應用您希望的格式,否則將應用默認格式。

嘗試這個,

  @Html.TextBoxFor(model => model.InspectionReport.InspectionDate, "{0:dd-MMM-yyyy}", htmlAttributes: new { @type="date" })

暫無
暫無

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

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