C # Unix timestamp Conversion

Source: Internet
Author: User

Due to data import, when a mysql DATA table contains a Unix timestamp, it cannot be imported into the SQL server database. Later, it will first convert the time format through the C # program and then import it to the SQL server data table.

String timeStamp = "1191030513613 ";
DateTime dtStart = TimeZone. CurrentTimeZone. ToLocalTime (new DateTime (1970, 1, 1 ));
Long lTime = long. parse (timeStamp + "0000"); // note that the time format is 13 BITs followed by 4 "0 ", if the time format is 10 bits, add seven "0" s to the end. I don't know why. It is also equivalent to the Code Conversion written by others.
TimeSpan toNow = new TimeSpan (lTime );
DateTime dtResult = dtStart. Add (toNow );
Response. Write ("value:" + dtResult );
Response. End ();

 

Output: Value: 2007/9/29 9:48:33

Related Article

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.