Datagird How do I set the date format to YYYY-MM-DD format in the TemplateColumn type column?

Source: Internet
Author: User
Tags datetime

1. Bind timed Format Date method:
<asp:boundcolumn datafield= "Jointime" dataformatstring= "{0:YYYY-MM-DD}" >
<itemstyle width= "18%" > </itemstyle >
</asp:boundcolumn >

2. Data controls such as Datagrid/datalist format Date method:
E.item.cell[0]. Text = Convert.todatetime (e.item.cell[0]. Text). ToShortDateString ();

3. Use the string class to convert the date display format:
String.Format ("Yyyy-mm-dd", yourdatetime);

4. Convert date display format with convert method:
Convert.todatetime ("2005-8-23"). Tostring

("YyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); Support for traditional databases

5. Convert the date display format directly with the ToString method:
DateTime.Now.ToString ("Yyyymmddhhmmss");
DateTime.Now.ToString ("Yyyy/mm/dd hh:mm:ss")

6. Show only Month
DataBinder.Eval (Container.DataItem, "StartTime", "{0:yyyy-m}")

7. Display all parts of the time, including: Month Day minutes and seconds
<asp:boundcolumn datafield= "Payment Time" headertext= "Payment Time"
dataformatstring= "{0:yyyy-mm-dd HH24:mm:ss}" >
</asp:BoundColumn>

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.