1. 首页
  2. 人工智能
  3. 论文/代码
  4. 使用Node.js获取当前时间的代码示例

使用Node.js获取当前时间的代码示例

上传者: 2023-03-09 05:02:18上传 TXT文件 688B 热度 9次
// 使用Node.js获取当前时间的代码示例
const now = new Date();
const year = now.getFullYear().toString().padStart(4, '0');
const month = (now.getMonth() + 1).toString().padStart(2, '0');
const day = now.getDate().toString().padStart(2, '0');
const hour = now.getHours().toString().padStart(2, '0');
const minute = now.getMinutes().toString().padStart(2, '0');
const second = now.getSeconds().toString().padStart(2, '0');
const currentTime = `${year}${month}${day}${hour}${minute}${second}`;
console.log(currentTime);
用户评论