日期时间格式

本文关键字:格式 时间 日期 | 更新日期: 2023-09-27 17:51:09

这是我的类:

 public partial class Post
{
    public Post()
    {
        this.PostImages = new HashSet<PostImage>();
        this.PostMappings = new HashSet<PostMapping>();
    }
    public int ID { get; set; }
    public string Title { get; set; }
    public string TitleMenu { get; set; }
    public string Preview { get; set; }
    public string Content { get; set; }
    public Nullable<int> Display { get; set; }
    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    public Nullable<System.DateTime> DateAdded { get; set; }
    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    public Nullable<System.DateTime> DateHide { get; set; }
    public Nullable<int> PozitionMenu { get; set; }
    public string Username { get; set; }
    public virtual ICollection<PostImage> PostImages { get; set; }
    public virtual ICollection<PostMapping> PostMappings { get; set; }
}

我想更新列DateHide

   @Html.TextBoxFor(model => model.DateHide, new { @class = "jquery_datepicker", @Value = (!Model.DateHide.HasValue ? "" : Model.DateHide.Value.ToString("dd/MM/yyyy"))})
     $('.jquery_datepicker').datepicker({ dateFormat: "dd/mm/yy" });

我添加了web.config:

<globalization culture="en-US" />

我仍然得到错误:

值'20/02/2014'对DateHide无效

日期时间格式

replace

$('.jquery_datepicker').datepicker({ dateFormat: "dd/mm/yy" });

$('.jquery_datepicker').datepicker({ dateFormat: "mm/dd/yy" });

这将以"02/20/2014"的格式将日期传递给模型。

我把

 @Html.TextBoxFor(model => model.DateHide, new { @class = "jquery_datepicker", @Value = (!Model.DateHide.HasValue ? "" : Model.DateHide.Value.ToString("dd/MM/yyyy"))})

  <span class="jquery_datepicker">    @Html.EditorFor(model => model.DateHide, new { @class = "jquery_datepicker", @Value =Model.DateHide, displayMode })</span>

$('.jquery_datepicker').datepicker({ dateFormat: "dd/mm/yy" });

 $('.jquery_datepicker input').datepicker({ dateFormat: "dd/mm/yy" });

现在它工作了!但我不知道为什么。EditorForTextboxFor的区别是什么?