. NET timestamps convert to each other (accurate to milliseconds)

Source: Internet
Author: User

Here to record a timestamp of the mutual conversion method, the Internet has been looked up, the basic is not accurate to milliseconds, my basic can meet the accuracy to the millisecond level, the code is as follows:

1 /// <summary>2         ///Unix timestamp converted to datetime3         /// </summary>4         PrivateDateTime Converttodatetime (stringtimestamp)5         {6System.DateTime time =System.DateTime.MinValue;7             //accurate to milliseconds8             //time stamp turns into time9DateTime start = TimeZone.CurrentTimeZone.ToLocalTime (NewSystem.DateTime (1970,1,1));Ten             Try One             { ATime = timestamp. Length = =Ten? Start. AddSeconds (Long. Parse (timestamp)): Start. Addmilliseconds (Long. Parse (timestamp)); -             } -             Catch(Exception ex) the             { -                 returnStart//conversion failed -             } -             returnTime ; +         } -  +         /// <summary> A         ///datetime conversion to UNIX timestamp at         /// </summary> -         /// <param name= "Time" ></param> -         /// <returns></returns> -         Private stringConverttimestamp (DateTime time) -         { -             DoubleIntresult =0; inSystem.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (NewSystem.DateTime (1970,1,1)); -Intresult = (Time-startTime). TotalMilliseconds; to             returnMath.Round (Intresult,0). ToString (); +}


It is hereby marked with the hope that there will be fewer detours for those who help. THS:-);

. NET timestamps convert to each other (accurate to milliseconds)

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.