// add local time zone offset // get UTC time in msec utc = d.getTime() + (d.getTimezoneOffset() * 60000); // create new Date object for different city // using supplied offset nd = new Date(utc + (3600000*offset)); // return time as a string return "The local time in ...
//北京是getZoneTime(8),纽约是getZoneTime(-5),班加罗尔是getZoneTime(5.5). 偏移值是本时区相对于格林尼治所在时区的时区差值functiongetZoneTime(offset){//取本地时间varlocaltime =newDate();//取本地毫秒数varlocalmesc =localtime.getTime();//取本地时区与格林尼治所在时区的偏差毫秒数varlocalOffset =...
localTime = d.getTime(); localOffset=d.getTimezoneOffset()*60000; //获得当地时间偏移的毫秒数 utc = localTime + localOffset; //utc即GMT时间 offset =10; //以夏威夷时间为例,东10区 hawaii = utc + (3600000*offset); nd = new Date(hawaii); document.writeln("Hawaii time is " + nd.t...
var gmtHours =d.getTimezoneOffset()/60 document.write("The local time zone is: GMT " + gmtHours) </script> 输出: The local time zone is: GMT -8 亲自试一试 getTimezoneOffset() 如何使用 getTimezoneOffset() 根据 GMT 来取得本地时区。 JavaScript Date 对象 javascript...
getLocalTime (1642471746435) //'2022/1/18 上午10:09:06' 方法二:生成'yyyy-MM-dd hh:mm:ss '格式 先转换为data对象,然后利用拼接正则等手段来实现: function getData(n){ n=new Date(n) return n.toLocaleDateString().replace(/\//g, "-") + " " + n.toTimeString().substr(0, 8) ...
算出时差,并转换为毫秒: var offset2 = new Date().getTimezoneOffset()* 60 * 1000; //算出现在的时间: var nowDate2 = new Date().getTime(); //此时东2区的时间 var currentZoneDate = new Date(nowDate2 + offset2 + zoneOffset*60*60*1000); console.log("东2区现在是:"+currentZone...
localOffset=d.getTimezoneOffset()*60000; //获得当地时间偏移的毫秒数 utc = localTime + localOffset; //utc即GMT时间 offset =10; //以夏威夷时间为例,东10区 hawaii = utc + (3600000*offset); nd = new Date(hawaii); document.writeln("Hawaii time is " + nd.toLocaleString() + <br>");...
getTimezoneOffset() 方法可返回格林威治时间和本地时间之间的时差,以分钟为单位。例如,如果时区为 GMT+2, 将返回-120 。注意: 由于使用夏令时的惯例,该方法的返回值不是一个常量。提示: 协调世界时,又称世界统一时间,世界标准时间,国际协调时间,简称UTC(Universal Coordinated Time)。
<script type="text/javascript"> var d = new Date() var gmtHours = d.getTimezoneOffset()/60 document.write("The local time zone is: GMT " + gmtHours) </script> 1. 2. 3. 4. 5. 6. 7. 输出: The local time zone is: GMT -8...
// subtract local time zone offset // get UTC time in msec var utc = d.getTime()...