简体   繁体   中英

Pass “dd-MMM-yyyy” to datetime by post method

How Can I pass "dd-MMM-yyyy" Date format to DateTime by Post method?

[DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime? SomeDate { get; set; }

Format date from model:

[DisplayFormat(DataFormatString = "{0:MMM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime? SomeDate { get; set; }

You can format date in View file by following way

<span>@Convert.ToDateTime(SomeDate).ToString("MMM-yyyy")</span>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM