On the problem of displaying time date format in GridView-Practical tips

Source: Internet
Author: User
Tags time and date

The following are the most commonly used dates, time formats for the GridView

Form

Grammar

Results

Comments

Digital

{0:N2}

12.36

Digital

{0:n0}

13

Currency

{0:C2}

$12.36

Currency

{0:C4}

$12.3656

Currency

"¥{0:n2}"

¥12.36

Scientific counting method

{0:E3}

1.23E+001

Percentage

{0:p}

12.25%

P and p present the same.

Date

{0:D}

November 25, 2006

Date

{0:D}

2006-11-25

Date

{0:f}

November 25, 2006 10:30

Date

{0:f}

November 25, 2006 10:30:00

Date

{0:s}

2006-11-25 10:30:00

Time

{0:t}

10:30:00

When working in the GridView, be aware of the following aspects (take {0:d} as an example)

1. columns to bind if the boundfiled type is simple (as follows)

<asp:boundfield datafield= "SJ" headertext= "Time" readonly= "True" dataformatstring= "{0:d}"/>

The format shown is still 2006-11-25 0:00:00 to achieve the effect we want

2. the column to be bound must be a template column as follows: So you can see the effect we want to see: 2006-11-25

<asp:templatefield headertext= "Time" >

  <EditItemTemplate>

     <asp:label id= "Label1" Server "text= ' <%# Eval (" SJ "," {0:d} ")%> ' ></asp:Label>

</EditItemTemplate>

< itemtemplate>

     <asp:label id= "Label2" runat= "server" text= ' <%# Bind ("SJ", "{0:d}")%> ' ></asp: label>

</ItemTemplate>

</asp:TemplateField>

The above analysis of the GridView display time and date format of the problem is small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

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.