更新如何在JavaScript中获取UTC时间戳?

时间:2014-09-23 01:08:17

标签: javascript utc seconds

关于此链接和信息。 :

How do I get a UTC Timestamp in JavaScript?

我无法向绅士发布更新,你给了我一些暗示,可以做些什么来提高答案:

我感谢: https://stackoverflow.com/users/376535/shiplu-mokadd-im shiplu.mokadd.im 29.1k33797

你也可以利用getTimezoneOffset和getTime,

来做到这一点
x = new Date()
var UTCseconds = (x.getTime() + x.getTimezoneOffset()*60*1000)/1000;

感谢您拨打TIMEZONEOFFSET。我做了一个改进。

 // 20140922 arf made another piece of server side classic asp work.

// I prefer moving both sides of equation to seconds.

x = new Date()
var UTCseconds = ( (x.getTime()/1000) + (x.getTimezoneOffset()/60) );
return UTCseconds

//来自其他帖子的样本

<script language='Javascript' runat='server'>
   function jsGetUTCTime() {
    //var d = new Date();
    //return d.toUTCString();

    x = new Date()
    var UTCseconds = ( (x.getTime()/1000) + (x.getTimezoneOffset()/60) );
    return UTCseconds

  }
</script>
<script language='VBScript' runat='server'>
Function getUTCTime()
    ' Use JScript to get the current GMT time stamp
    getUTCTime = jsGetUTCTime()
End Function
</script>

< %
m_utc_time_stamp = getUTCTime()
% >

1 个答案:

答案 0 :(得分:0)

我认为你正在寻找这个:

UnixTimeStamp = DateDiff("s","01/01/1970",Now()) * 1000