utc.js

来自「这是《JavaScript学习源代码》一书的源代码」· JavaScript 代码 · 共 20 行

JS
20
字号
// create a new Date object
var now = new Date();

// get local time in hours
var hh = now.getHours();

// get the Universal time in hours
var utc_hh = now.getUTCHours();

// get minutes and seconds
var mn = now.getMinutes();
var ss = now.getSeconds();

// ensure there are two digits for the minute value
if( mn <= 9 ) mn = "0" +mn;  

// display both times
var wet = "Athens time: "+hh+": "+mn+": "+ss+"\n\n";
var utc = "Universal time: "+utc_hh+": "+mn+": "+ss;
alert( wet + utc );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?