在PhantomJS中预先设置浏览器时区

我在我的nodejs代码中使用了PhantomJS作为subprocess预编译,并且每次对其进行栅格化时都需要为浏览器设置一个TZ。

它作为一个subprocess执行,如下所示:

childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) { // handle results }); 

调用函数时无法指定TZ。

任何想法如何实现?

开始了! 使用execFile函数的options参数,并将自定义的TZ=Europe/London到subprocess的环境中。

index.js

 const execFile = require('child_process').execFile const env = Object.assign(process.env, { 'TZ': 'Europe/London' }) const child = execFile('./env-test.js', { env }, (error, stdout, stderr) => { if (error) { throw error; } console.log(stdout); }); 

env-test.js(应该是可执行的chmod +x env-test.js

 #!/usr/bin/env node console.log(new Date().toString())