The UNIX timestamp is stored in the database, for example (1358932051). The normal time display mode (17:07:31) is displayed on the front-end page.
The conversion method is as follows:
Code displayed on the front end (that is, the record time field for reading data ):
1 <td>2 <%#ToDateTime(Eval("time"))3 </td>
Time displayed on the front-end
Code displayed in the background:
A custom method is used to convert a Unix timestamp to a normal time, as follows:
1 /// <summary> 2 // UNIX timestamp conversion method 3 /// </Summary> 4 /// <Param name = "timestamp"> </param> 5 /// <returns> </returns> 6 public static datetime todatetime (Object timestamp) 7 {8 long Lon = 0; 9 long. tryparse (timestamp. tostring (), Out Lon); 10 datetime dtstart = timezone. currenttimezone. tolocaltime (New datetime (1970, 1, 1); 11 long ltime = long. parse (Lon. tostring () + "0000000"); 12 timespan tonow = new timespan (ltime); 13 return dtstart. add (tonow); 14}
Convert UNIX timestamp to normal time function