public string GetTime()
{
Int64 retval = 0;
DateTime st = new DateTime(1970, 1, 1);
TimeSpan t = (DateTime.Now.ToUniversalTime() - st);
retval = (Int64)(t.TotalMilliseconds + 0.5);
return retval.ToString();
}
{
Int64 retval = 0;
DateTime st = new DateTime(1970, 1, 1);
TimeSpan t = (DateTime.Now.ToUniversalTime() - st);
retval = (Int64)(t.TotalMilliseconds + 0.5);
return retval.ToString();
}
在Net中的实际测试代码
MSScriptControl.ScriptControlClass sc = new MSScriptControl.ScriptControlClass();
sc.Language = "javascript";
object obj = sc.Eval("new Date().getTime();");
然后比较两个得到的值。
我测试的结果是,差距在两毫秒。
参考自:http://bytes.com/topic/net/answers/796411-gettime-method-c
MCBoy http://bytes.com/profile/248458/mcboy/
的回复。
已测试,通过。
html测试代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
</head>
<body>
<script type="text/javascript" language="javascript">
function gettime() {
var time = new Date().getTime();
alert(time);
}
</script>
<input type="button" onclick="gettime()" name="test" value="获取当前时间" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
</head>
<body>
<script type="text/javascript" language="javascript">
function gettime() {
var time = new Date().getTime();
alert(time);
}
</script>
<input type="button" onclick="gettime()" name="test" value="获取当前时间" />
</body>
</html>
本文转自火地晋博客园博客,原文链接:http://www.cnblogs.com/yelaiju/archive/2011/09/04/2166671.html,如需转载请自行联系原作者