JS和C#之间的时间戳转换
时间的JS时间变成在C #时间戳,然后C #时间戳转换成js的时间js中的时间戳
复制代码代码如下所示:
VaR DT =新的日期(。时间)(); / /时间戳
C #时间戳转时间
复制代码代码如下所示:
日期时间dtstart = timezone.currenttimezone.tolocaltime(新的日期(1970, 1, 1));
长时间=长。解析(DT + 0000); / /注,时间格式为13后面加40
TimeSpan现在=新的时间(时间);
日期时间dtresult = dtstart。加(现在); / /转换时间
-------------------------------------------------------------------------------
C #传递时间的时间戳
复制代码代码如下所示:
系统。日期开始时间= timezone.currenttimezone.tolocaltime(新系统。日期时间(1970, 1, 1,0, 0, 0,0));
/ / intresult =。totalmilliseconds(时间-开始时间);
日期时间dtresult / /采集时间
长= T(dtresult.ticks -开始时间。蜱) / / / 10000;除10000调整为13
js
复制代码代码如下所示:
var =新的日期(数据)
警报(formatDate(D));
时间格式
功能formatDate(现在){
VaR年= now.getfullyear();
VaR月= now.getmonth()+ 1;
var date = now.getdate();
无功功率= now.gethours();
VaR分钟= now.getminutes();
无功二= now.getseconds();
返回年份++++小时+:+分钟+:+秒;
}
代码非常简单,但是非常实用,而且这些人正在寻找它。