Convert JS timestamp to time in C#, and then convert the timestamp in C# to time in JS
Timestamp in JS
The code copy is as follows:
var dt = new Date().getTime();// Timestamp
C# Timestamp to time
The code copy is as follows:
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime( new DateTime(1970, 1, 1));
long lTime = long.Parse(dt + "0000"); //Instructions, the time format is 13 bits and add 4 "0" to the next. If the time format is 10 bits, add 7 "0" to the next. As for why I don't know much, it is also converted according to the code written by others.
TimeSpan toNow = new TimeSpan(lTime);
DateTime dtResult = dtStart.Add(toNow); //Get the converted time
-------------------------------------------------------------------------------
C# Time to Time Stamp
The code copy is as follows:
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;//Adjust 10000 to 13 bits
JS
The code copy is as follows:
var d = new Date(data); //Time stamp to time
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;
}
The code is super simple, but it is very practical. Please refer to it.