gpt4 book ai didi

node.js - 如何为 Heroku 设置时区

转载 作者:搜寻专家 更新时间:2023-10-31 22:44:46 24 4
gpt4 key购买 nike

我编写了一个在 Heroku(全局)上运行的 Node.js 服务器。在我的本地主机上一切正常,但由于 Heroku 的时区是 UTC,我的函数现在运行不正确。有人可以帮我设置默认时区吗?

这是我的代码:

router.get('/year/:yyear/:mmonth/:ddate/:hhours/:mminute/:sseconds/:fireTitle/:fireBody', function(req, res) {

var year1 = req.params.yyear;
var month1 = (req.params.mmonth)-1;
var date1 = req.params.ddate;
var hours1 = req.params.hhours;
var minute1 = (req.params.mminute);
var seconds1 = req.params.sseconds;


var datetime = new Date((new Date)*1 - 1000*3600*5.5 );


var responseObject= "Your Function has been set for : "+year1+month1+date1+hours1+minute1+seconds1 +" date "+ datetime;

var cron = require('node-schedule');
var date = new Date(year1, month1, date1, hours1, minute1, seconds1);

cron.scheduleJob(date, function(){

var request = require("request");

request("This Function will run" , function(error, response, body) {
console.log(body);
});
});

res.send(responseObject);

});


module.exports = router;

最佳答案

你可以在 heroku 中为你的应用做这样的事情

heroku config:add TZ="America/Los_Angeles"

http://blog.pardner.com/2012/08/setting-the-default-time-zone-for-a-heroku-app/

关于node.js - 如何为 Heroku 设置时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44715072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com