Current location - Training Enrollment Network - Early education courses - What type of date data should be accepted in the database?
What type of date data should be accepted in the database?
1. If the data type of the time stored in the database is datetime, then the time format conversion in the background code (*.aspx.cs) is avoided, and the task of format conversion is put on the interface code (*). aspx)。

No matter what format the acquired time is, don't do any operation (such as assignment) on the value of this time in the background. Otherwise, the system will implicitly convert the time), but format it directly in the interface code (*). Aspx) through methods such as DataBinder and Eval:

Background key code:

& ltspan style="white-space:pre " >& lt/span>。 DataTable dt = new NewsManager()。 select byid(newsid); //The dt obtained here is the data directly queried from the database.

& ltspan style="white-space:pre " >& lt/span>。 News reports. DataSource = dt

News reports. DataBind();

Front key code:

& ltspan style="white-space:pre " >& lt/span>。 & ltASP:Repeater ID = " repNews " runat = " server " & gt;

& ltItemTemplate & gt

& ltp class="con_time " >

Release time:

& lt%# DataBinder。 Evaluation (container. DataItem," createTime "," { 0:yyyy-MM-DD HH:MM:ss } " % & gt; & lt%- where createTime is the field name in dt above-%>

& lt/p & gt;

& lt/item template & gt;

& lt/asp: repeater & gt