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)