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;
}
Related articles
- Vuejs time conversion code and timestamp to time string
- Javascript timestamp and date string conversion code (super simple)
- js get time and achieve conversion between string and timestamp
- The js implementation converts the timestamp to yyyy-MM-dd hh: mm format (es6 syntax)
- Convert between js timestamp and date format
- JS get time related functions and conversion between timestamp and time and date
- JS convert time seconds to day hours minutes seconds
Trends