6 Methods of time formatting in ASP.net detailed summary _ Practical skills

Source: Internet
Author: User
Tags add time datetime
1. Data Control Binding Time format Date method:
Copy Code code as follows:

<asp:boundcolumn datafield= "Addtime" headertext= "Add Time" dataformatstring= "{0:yyyy-mm-dd HH:mm}></asp: Boundcolumn>
<asp:boundfield datafield= "Addtime" headertext= "Add Time" dataformatstring= "{0:yyyy-mm-dd}"/>

2. Data binding with DataBinder.Eval:
Copy Code code as follows:

DataBinder.Eval (Container.DataItem, "Addtime", "{0:YYYY-MM-DD}")

3. Convert date display format directly with the ToString method:
Copy Code code as follows:

DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss")

4. Convert date display format with string class:
Copy Code code as follows:

String.Format ("{0:yyyy-mm-dd}", DateTime.Now)

5. Convert date display format with DateTime.Parse method
Copy Code code as follows:

DateTime.Parse ("2012-2-22"). ToString ("Yyyy-mm-dd")

6. Convert date display format with Convert.todatetime method:
Copy Code code as follows:

Convert.todatetime ("2012-12-21"). ToString ("Yyyy-mm-dd")

Standard DateTime format specifier
HTTP://MSDN.MICROSOFT.COM/ZH-CN/LIBRARY/AZ4SE3K1 (v=vs.80). aspx
Custom DateTime format specifier
HTTP://MSDN.MICROSOFT.COM/ZH-CN/LIBRARY/8KB3DDD4 (v=vs.80). aspx
Related Article

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.