time.js

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

JS
21
字号
// create a new Date object
var now = new Date();
// extract the time information
var hh = now.getHours();
var mn = now.getMinutes();
var ss = now.getSeconds();
var ms = now.getMilliseconds();
// default welcome message
var hi = "Good Morning";
// welcome if after noon
if( hh > 11 ) hi= "Good Afternoon";
// welcome if after 5 p.m.
if( hh > 17 ) hi= "Good Evening";
//hi+="\nWelcome to the Acme website";

// display welcome message and the current time
var tim = hi + "\n";
tim += "Hours: " +hh+ "\n";
tim += "Minutes: " +mn+ "\n";
tim += "Seconds: " +ss+ "." +ms;
alert(tim);

⌨️ 快捷键说明

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