javascript - 在 PhantomJS 预构建中设置浏览器时区

标签 javascript node.js timezone phantomjs

我在我的nodejs代码中使用预构建的PhantomJS作为子进程,并且每次光栅化时都需要为浏览器设置一个TZ。

它作为子进程执行,如下:

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

调用函数时无法指定 TZ。

知道如何实现这一目标吗?

最佳答案

我们开始吧!使用options argument of the execFile function并将自定义 TZ=Europe/London 添加到子进程的环境中。

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())

关于javascript - 在 PhantomJS 预构建中设置浏览器时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42778907/

相关文章:

Javascript Raphael SVG map 在 IE 7/8 中加载速度非常慢

javascript - 从 Firebase 加载数据时,AngularJS 过滤器不起作用

javascript - 在 jQuery 中保存用户输入?

python - 如何自动获取本地时区的时区偏移量?

php - 如何在多个不同的 php 环境中运行 PHPunit 测试套件?

c# - Azure 中的时区偏移不正确

Javascript初学者语法问题

javascript - Mongoose:向嵌套对象添加属性

node.js - 开发中需要在 "/static"前追加子目录

node.js - NodeJS 垃圾邮件 GET - REST API