Detailed summary of 6 ways to format time in "Go" asp

Source: Internet
Author: User
Tags add time

1. Data Control Binding Format Date method:

The code is as follows:

 <asp:boundcolumn datafield= " addtime   Headertext=   Dataformatstring="  {0 : Yyyy-mm-dd hh:mm}></asp:boundcolumn>  <asp:boundfield datafield=  addtime   Headertext=   Dataformatstring="  {0 : yyyy-mm-dd}  /> 

2. Use DataBinder.Eval for data binding:

The code is as follows:

DataBinder.Eval (Container.DataItem,"addtime","{0:yyyy-mm-dd}" )

3. Convert the date display format directly with the ToString method:

The code is as follows:

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

4. Use the string class to convert the date display format:

The code is as follows:

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

5. Convert the date display format using the DateTime.Parse method

The code is as follows:

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

6. Convert the date display format using the Convert.todatetime method:

The code is as follows:

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

Standard DateTime format specifier
Custom DateTime format specifier

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: 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.