为石英简单触发器设置时区 [英] Setting a timezone for quartz simple trigger

查看:77
本文介绍了为石英简单触发器设置时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为包含时区的作业设置石英触发器.例如.我需要将其设置为 2012 年 8 月 27 日 15:00 欧洲/阿姆斯特丹时区.我的服务器使用 UTC.

I need to set a quartz trigger for a job that includes a timezone. E.g. I need to set it for 27 August 2012 at 15:00 Europe/Amsterdam timezone. My server works on UTC.

我相信 SimpleTrigger 是我所需要的,但我不知道如何为其设置时区.

I believe a SimpleTriggeris what I need, but I do not know how to set a timezone for it.

有什么想法吗?

推荐答案

SimpleTrigger 的触发时间基于配置的开始时间.

SimpleTrigger's fire time is based on the configured start time.

开始时间指定为 java.util.Date,它实际上只是自 1970 年 1 月 1 日 00:00:00.000 GMT 以来以毫秒为单位指定的时间.

The start time is specified as a java.util.Date, which is really just time specified in milliseconds since Jan 1, 1970 00:00:00.000 GMT.

如果在 2010 年 10 月 23 日 8:13:45 EST 您的代码执行 new Date(),并将结果设置为开始时间,Quartz 将存储以毫秒为单位的值 (1287839625000) 作为开始时间,然后无论调度程序在哪个时区运行,触发器都将在 2010 年 10 月 23 日 8:13:45 EST 触发.

If, at Oct 23, 2010 8:13:45 EST your code executes new Date(), and sets the result as the start time, Quartz will store as the start time the value in milliseconds (1287839625000), and then the trigger will fire at Oct 23, 2010 8:13:45 EST regardless of which timezone the scheduler is running in.

如果您使用 java.util.Calendar 定义特定时区中的日期和时间,然后将其转换为日期,则其工作方式完全相同:如果您指定了 2010 年 10 月 23 日 8:13:45 并且日历的时区是 EST,那么结果毫秒值将再次为 1287839625000.但如果时区是 PST(但日期时间相同),毫秒值将是 1287850425000(3 小时后).

If you use java.util.Calendar to define a date and time in a particular time zone, and then convert that to a Date, it will work exactly the same: If you have specified Oct 23, 2010 8:13:45 and the Calendar's time zone is EST then the resulting milliseconds value will again be 1287839625000. But if the timezone was PST (but the date time the same) the milliseconds value would be 1287850425000 (3 hours later).

只需确保运行 Quartz 的系统时钟已正确设置并由操作系统维护为 UTC.

Just make sure the system clock where Quartz is running has been correctly set and is maintained as UTC by the operating system.

这篇关于为石英简单触发器设置时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆