我试过这个:
puppeteer.launch({
env: {
TZ: 'Australia/Melbourne',
...process.env
}
});
不要为我工作。 whoer.net 看到我的实际系统时间。
编辑:关于 https://github.com/nodejs/node/issues/4230 的一些信息
This code works well on Linux but does not work on Windows:
process.env.TZ = 'UTC';
console.log(new Date());
On Windows, I see timezone from my OS.
最佳答案
根据Puppeteer documentation , 你可以使用 page.emulateTimezone()
:
page.emulateTimezone()
timezoneId
<?string> Changes the timezone of the page. See ICU’s metaZones.txt for a list of supported timezone IDs. Passingnull
disables timezone emulation.returns: <Promise>
例如:
await page.emulateTimezone('America/Chicago');
关于javascript - 如何使用 Puppeteer 设置、更改或阻止时区(系统时间)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53027538/