-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeline.js
45 lines (35 loc) · 1.09 KB
/
timeline.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
42
43
44
45
var fs = require("fs");
// while(true) {
// console.log("")
// var content = process.stdin;
// console.log(content);
// }
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function timeline() {
rl.question('请输入此刻的念头: ', (answer) => {
// TODO: Log the answer in a database
fs.appendFileSync("./TIMELINE",formatDate(new Date()) +"\n\t"+ answer +"\n");
console.log(new Date().toISOString() +"\n"+ answer);
// rl.close();
timeline();
});
}
process.on("close", function() {
console.log("process exit")
rl.close()
})
timeline()
/**
* 时间格式化工具
* @example 2017-07-13 00:00:00
*/
function formatDate(date, isDate) {
if (Object.prototype.toString.call(date) !== "[object Date]") {
throw new TypeError("date is not Date type");
}
return isDate?(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate()):(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds())
}