//本文件用于放置常用函数 function GetNowData() { // 获取当前时间 var currentTime = new Date(); // 分别获取年、月、日、时、分、秒 var year = currentTime.getFullYear(); var month = padZero(currentTime.getMonth() + 1); // 月份是从0开始的,所以要加1 var day = padZero(currentTime.getDate()); var hours = padZero(currentTime.getHours()); var minutes = padZero(currentTime.getMinutes()); var seconds = padZero(currentTime.getSeconds()); // 打印输出当前时间 return ("当前时间:" + year + "-" + month + "-" + day + "-" + hours + "-" + minutes + "-" + seconds); } // 补零函数,不用导出 function padZero(num) { return num < 10 ? '0' + num : num; } function multiply(x, y) { return x * y; } module.exports = { GetNowData, multiply }; /* 其他页面调用方法是: 首先引入 const common = require('../../api/common.js'); 然后调用,返回值就是result common.GetNowData(); */