In the project development process, sometimes encounter different programs to call each other data, the data will inevitably contain time, For example, asp.net call PHP, involved in time to do some processing, PHP program in general access are Unix time, unlike ASP.net storage is the month and a half minutes, so you need to do a transformation, the code is as follows:
First, convert system time to UNIX timestamp
Copy Code code as follows:
DateTime Dtstart = TimeZone.CurrentTimeZone.ToLocalTime (new DateTime (1970,1,1));
DateTime Dtnow = DateTime.Parse (DateTime.Now.ToString ());
TimeSpan Tonow = dtnow.subtract (Dtstart);
String timeStamp = ToNow.Ticks.ToString ();
TimeStamp = timestamp.substring (0,timestamp.length-7);
Second, the Unix time stamp into the system time
Copy Code code as follows:
String timeStamp = "1288368000";
DateTime Dtstart = TimeZone.CurrentTimeZone.ToLocalTime (new DateTime (1970,1,1));
Long ltime = long. Parse (TimeStamp + "0000000");
TimeSpan Tonow = new TimeSpan (ltime);
DateTime Dtresult = Dtstart.add (Tonow);
These two methods are relatively simple, you can encapsulate them into static functions, call directly.