Home>

Recently working on a project,Need js timestamp to convert to time in c#,Then I converted the timestamp in c#to the time of js, and carefully studied the points of attention in the conversion between js and c#.Recorded here,Those in need are taken away by themselves.

js timestamp into time in c#,Then convert the timestamp in c#to the time of js

Timestamp in js

var dt=new date (). gettime ();//time stamp

c#timestamp turn time

datetime dtstart=timezone.currenttimezone.tolocaltime (new datetime (1970, 1, 1));
 long ltime=long.parse (dt + "0000");//Explanation, the time format is 13 bits followed by 4 "0", if the time format is 10 bits followed by 7 "0" Why I'm not quite sure,It is also modeled after the code written by others
 timespan tonow=new timespan (ltime);
 datetime dtresult=dtstart.add (tonow);//Get the time after conversion

-------------------------------------------------- -----------------------------

c#time to timestamp

system. datetime starttime=timezone.currenttimezone.tolocaltime (new system. datetime (1970, 1, 1, 0, 0, 0, 0));
 //intresult=(time- starttime) .totalmilliseconds;
datetime dtresult //Get time
long t=(dtresult.ticks-starttime.ticks)/10000;//adjusted to 13 bits except 10000

js

var d=new date (data);
 alert (formatdate (d));
//format time
function formatdate (now) {
 var year=now.getfullyear ();
 var month=now.getmonth () + 1;
 var date=now.getdate ();
 var hour=now.gethours ();
 var minute=now.getminutes ();
 var second=now.getseconds ();
 return year + "-" + month + "-" + date + "" + hour + ":" + minute + ":" + second;
 }
  • Previous Talk about JavaScript anonymous functions and closures
  • Next jquery checkbox Checked bug problem solution and analysis
  • Trends