-
Notifications
You must be signed in to change notification settings - Fork 12
/
tool.js
41 lines (38 loc) · 1.1 KB
/
tool.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var process = require('child_process');
function Tool() {}
Tool.prototype = {
// 执行命令行
_cmd: function(shell) {
return new Promise(function(resolve, reject) {
process.exec(shell, function(error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
}
console.log(stdout, stderr)
resolve();
});
});
},
// 返回日期
_date: function(date, flag) {
var me = this;
if (!date) {;
return false;
} else {
if (flag && flag == true) {
var dt = new Date(date);
return (dt.getFullYear() + "-" + me._reset_num(dt.getMonth() + 1) + "-" + me._reset_num(dt.getDate()));
} else {
var dt = new Date(date);
return (dt.getFullYear() + "-" + me._reset_num(dt.getMonth() + 1) + "-" + me._reset_num(dt.getDate()) + " " + me._reset_num(dt.getHours()) + ":" + me._reset_num(dt.getMinutes()) + ':' + me._reset_num(dt.getSeconds()));
}
}
},
_reset_num: function(num) {
if (num < 10) {
return "0" + num;
}
return num;
},
};
module.exports = Tool;