📜  p5.js |小时()函数

📅  最后修改于: 2022-05-13 01:56:48.130000             🧑  作者: Mango

p5.js |小时()函数

p5.js 中的hour()函数用于从系统时钟返回当前小时。它返回一个介于 0 到 23 之间的整数值。

句法:

hour()

参数:此函数不接受任何参数。

返回值:此函数返回一个表示当前小时的整数值。

下面的程序说明了 p5.js 中的 hour()函数:

示例:此示例使用 hour()函数从系统时钟返回当前小时。

function setup() {
  
    // Create Canvas of size 270*80
    createCanvas(270, 80);
}
  
function draw() {
      
    // Set the background color
    background(220);
      
    // Initialize the parameter with
    // current hour
    let h = hour();
      
    // Set the font size
    textSize(16);
      
    // Set the font color
    fill(color('red'));
      
    // Display result
    text("Current hour is : " + h, 50, 30);
}

输出:

参考: https://p5js.org/reference/#/p5/hour