?
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,如需轉載請自行聯系原作者