mvc-Processing Time format

Source: Internet
Author: User

The first method is to set a template for the time display and then call the template where it needs to be displayed.

1. Under the Share folder, create a folder DisplayTemplates

2. Under the DisplayTemplates folder, create a view longdatetime.cshtml

3. Enter the code in the View longdatetime.cshtml

@model System.DateTime

@Model. Tolongdatestring () Of course, the latter sentence can also be changed to @model.toshortdatestring () or other date formats.

4, in the need to display the date of the place, by the original

@Html. displayfor (ModelItem = Item. Posttime) replaced with

@Html. displayfor (ModelItem = Item. Posttime, "Longdatetime") This completes the display conversion of the time format. Displayed by the original display (2013/8/6-13:37:33) (August 6, 2013)

The second method: Add DisplayFormat attribute above the model class.

Such as:

[Display (Name = "Release Time:")]

[DisplayFormat (dataformatstring = "{0:yyyy mm month DD day}")]

Public virtual System.DateTime posttime {get;set;}

displayed, this format is still August 6, 2013.

mvc-Processing Time format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.