gpt4 book ai didi

asp.net - 如何仅存储 hh :mm in the datetime field?

转载 作者:行者123 更新时间:2023-12-02 21:30:06 24 4
gpt4 key购买 nike

我正在使用带有数据注释属性的codefirst。该模型如下所示:

    public class Incident
{
[Key]
public int IncidentId { get; set; }

[Display(Name = "Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mm}")]
public DateTime Date { get; set; }
}

创建 View :

    <div class="editor-label">
@Html.LabelFor(model => model.Date)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Date, "time")
@Html.ValidationMessageFor(model => model.Date)
</div>

当我尝试创建新模型时,我会在该字段附近收到验证消息。我什至尝试从创建方法将当前日期传递给 View ,但这没有帮助。有没有办法只存储 hh:mm (没有 dd/MM/yyyy)?

最佳答案

如果您真的只对一天中的时间感兴趣,那么也许可以使用 TimeSpan而不是日期时间

关于asp.net - 如何仅存储 hh :mm in the datetime field?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22528982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com