//JavaScript Node(12.x.x) var readline = require('readline') // 创建输入输出接口 const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }) // 监听控制台的输入 // 就是在用户输入一行 按下回车的时候就会触发的事件,他会将用户输入的数据通过回调函数传回来。 rl.on('line', function (line) { let year = line.substr(0,4) let month = line.substr(4,2) let date =line.substr(6) console.log("year="+year+"\n"+"month="+month+"\n"+"date="+date) rl.close() //关闭 readline.Interface 实例 })