The following are the most commonly used dates for the GridView, the time format
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 |
|
Note the following aspects when operating in the GridView (for example, {0:d})
1. The column to bind if it is purely boundfiled type (see below)
<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 bind must be a template column as follows: To see the effect we want to see: 2006-11-25
1 <Asp:templatefieldHeaderText= "Time">2 3 <EditItemTemplate>4 5 <Asp:labelID= "Label1"runat= "Server"Text= ' <%#Eval ("SJ", "{0:d}")%>' ></Asp:label>6 7 </EditItemTemplate>8 9 <ItemTemplate>Ten One <Asp:labelID= "Label2"runat= "Server"Text= ' <%#Bind ("SJ", "{0:d}")%>' ></Asp:label> A - </ItemTemplate> - the </Asp:templatefield>
View Code
Time date format issue in GridView