Several methods of time formatting in ASP.

Source: Internet
Author: User
Tags add time
1. Data Control Binding Format Date method:
<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. Use DataBinder.Eval for data binding:
DataBinder.Eval (Container.DataItem, "Addtime", "{0:YYYY-MM-DD}")

3. Convert the date display format directly with the ToString method:
DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss")

4. Use the string class to convert the date display format:
String.Format ("{0:yyyy-mm-dd}", DateTime.Now)

5. Convert the date display format using the DateTime.Parse method
DateTime.Parse ("2012-2-22"). ToString ("Yyyy-mm-dd")

6. Convert the date display format using the Convert.todatetime method:
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.