例子:

1
2
3
4
5
6
7
8
9
10
11
// 从 coscmd info <fileId> 命令的结果中抽取 Last-Modified 时间
const { spawn } = require('child_process');

const info = spawn('coscmd', ['info', cosId]);
info.stdout.on('data', (data) => {
data = data.toString();
let i = data.indexOf("Last")
let j = data.indexOf("GMT")
let s = data.substring(i + 22, j) + "GMT"
console.log(new Date(s))
})

Node.js官网链接