UNIX timestamp Conversion Method

Source: Internet
Author: User

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

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.