【发布时间】:2014-02-06 07:13:36
【问题描述】:
我在数据库中有一些字段,其中两个作为 DateTime 字段,我通过 GridView 中的“DataTable”检索它,如下面的代码所示
C#代码
var connection = new MySqlConnection(_TestMySqlConString);
string query1 = myQuery;
var cmd1 = new MySqlCommand(query1, connection);
connection.Open();
var dataTable1 = new DataTable();
var da1 = new MySqlDataAdapter(cmd1);
da1.Fill(dataTable1);
grdInvitationTendersList.DataSource = dataTable1;
grdInvitationTendersList.DataBind();
ASP 代码
<asp:GridView ID="grdList" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="R_NUMBER" OnRowCommand="grdList_RowCommand" >
<AlternatingRowStyle BackColor="White" />
<Columns>
....
<asp:BoundField DataField="TENDER_NUMBER" HeaderText="T_NUMBER" ReadOnly="True" SortExpression="T_NUMBER" Visible="TRUE"></asp:BoundField>
<asp:BoundField DataField="LAST_DATE_SUBMISSION" HeaderText="Last Date of Submission" ReadOnly="True" SortExpression="LAST_DATE_SUBMISSION" HeaderStyle-BorderStyle="Solid"
HeaderStyle-HorizontalAlign="Right" FooterStyle-BackColor="pink" FooterStyle-BorderColor="White" Visible="True" DataFormatString="{0:g}"></asp:BoundField>
......
</Columns>
LAST_DATE_SUBMISSION 是一个 dateTime 字段。
我的问题是我怎样才能在yyyy/MM//dd hh:mm:ss 中有日期时间,我必须转换culture 并在 GridView 中显示日期时间
*编辑 1:* I admit that my question is not cleared. Let me explain more, My second part of question is that "I have to convert the Datetime to other Calender type and then display in the GridView"
【问题讨论】:
-
您是否在询问如何独立于当前文化设置 DateTime 格式模式?
-
我要求我在数据库中有一个公历日期(通过数据表获取),并希望转换为其他日历类型,然后在 GridView 中显示。
-
查看我的答案的编辑 - DateTime 始终是有效的公历,但如果您使用具有不同日历系统的文化,它将自动转换。