CronJob使用时区

时间:2018-10-09 11:45:25

标签: node.js cron

我在NodeJs应用程序中使用CronJob。一切正常,除了我想根据特定时区触发CronJob。

    const membershipChangeCronJob = new CronJob({
    cronTime: '0 5 12 * * *',
    onTick: function () {
        console.log('********************************************');
        console.log('**********Membership Change Cron Job*************');
        console.log('********************************************');

        membershipeUpdate();

    },
    start: false
});

membershipChangeCronJob.start();

反正我可以在CronJob中使用矩时区吗?还是有其他解决方法

1 个答案:

答案 0 :(得分:3)

是的,您可以添加

的参数或键
  

timeZone

添加所需的时区

    private PrintingAction printingAction = null;

    @Override
    protected void init(int reportIndex) {
        if(reportIndex == 0){//Raw Material printout 
            ProductionProgram productionProgram = getUserData();
            printingAction = RawMaterialReportDesc.getInstance().newPrintingAction();
            printingAction.setObjectToPrint(productionProgram);
            printingAction.initLauncher();

        }else if(reportIndex == 1){//Production Steps
            ProductionProgram productionProgram = getUserData();
            printingAction = ProductionStepsReportDesc.getInstance().newPrintingAction();
            printingAction.setObjectToPrint(productionProgram);
            printingAction.initLauncher();

        }else if(reportIndex == 2){//Production Steps                   
            ProductionProgram productionProgram = getUserData();
            printingAction = FinishedProductsReportDesc.getInstance().newPrintingAction();
            printingAction.setObjectToPrint(productionProgram);
            printingAction.initLauncher();
        }
    }

    @Override
    protected void shut(int reportIndex) {
        if(printingAction != null){
            printingAction.dispose();
        }
    }

    @Override
    protected String getReportFileName(int reportIndex) {
        String fileName = null;
        PrnContext prnContext = ReportFactory.getInstance().findContext("PRODUCTION_CONTEXT");
        if (prnContext != null) {
            PrnLayout prnLayout = null;
            if(reportIndex == 0) {
                prnLayout = prnContext.getLayoutByName("RAW_MATERIAL");
            }else if(reportIndex == 1) {
                prnLayout = prnContext.getLayoutByName("STEPS");
            }else if(reportIndex == 2) {
                prnLayout = prnContext.getLayoutByName("FINISHED_PRODUCTS");
            }
            if (prnLayout != null) {
                fileName = printingAction != null ? 
                printingAction.getLauncher().getReportFileName(prnLayout) : null;   
            }
        }
        return fileName;
    }

    @Override
    protected JRFocObjectParameters getParams(int reportIndex) {
        JRFocObjectParameters params = null;
        if(reportIndex == 0 || reportIndex == 1 || reportIndex == 2){
            //I am using the same header FocObject for all 3 reports
            ProductionProgram productionProgram = getUserData();
            params = new JRFocObjectParameters(productionProgram);  
        }
    }

    @Override
    protected JRFocListDataSource getDataSource(int reportIndex) {
        JRFocListDataSource source = null;
        if(reportIndex == 0){//Raw material
            ProductionProgram productionProgram = getUserData();
            source = new JRFocListDataSource(productionProgram.getRawMaterialFocList());
        }else if(reportIndex == 1){//Production Steps
            ProductionProgram productionProgram = getUserData();
            source = new JRFocListDataSource(productionProgram.getProductionStepsFocList());
        }else if(reportIndex == 2){//Production Steps
            ProductionProgram productionProgram = getUserData();
            source = new JRFocListDataSource(productionProgram.getFinishedGoodsFocList());                  
        }

        return source;
    }

    @Override
    protected boolean next(int reportIndex) {
        return reportIndex <= 2;//Because we have 3 printouts 1,2,3
    }
};

可以在here中找到带有示例的文档