You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by loganathan <lo...@gmail.com> on 2013/09/16 08:14:20 UTC

Problem in converting Cron expression into proper date format.

I have cron expression like 0 05 14 * * ? to start the route.But what my
requirement is i have to convert the same cron expression into proper date
format.The following is the code used for converting cron expression into
date format.

 CronExpression cronExpression = new CronExpression("0 05 14 * * ?");
 Date date1 = cronExpression.getNextValidTimeAfter(new Date());
System.out.println("date1 date is>>>>>>..."+date1);

Note:My requirement is not next valid,invalid,next,current time for the cron
expression that i have mentioned above.need is exact date format eg:Mon Sep
16 14:15:00 IST 2013 for the above cron expression.

Like that whatever cron expression i have pass i need exact date format for
the cron expression.

Very Urgent.Anyone help is highly appreciated?



--
View this message in context: http://camel.465427.n5.nabble.com/Problem-in-converting-Cron-expression-into-proper-date-format-tp5739498.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem in converting Cron expression into proper date format.

Posted by loganathan <lo...@gmail.com>.
Thanks for your response.while i am using the below code(with spring) the
problem i am getting is suppose if today is tuesday but its showing date
format for next included time as "Wed Sep 18 10:55:00 IST 2013" But our
requirement is not showing next included time our need is to show exact date
format as "Tue Sep 17 10:55:00 IST 2013" if current day is tuesday.

with Spring

new CronSequenceGenerator("0 05 14 * * ?",TimeZone.getDefault())
   .next(new Date());

with Quartz

new Date(new CronCalendar("0 05 14 * * ?")
   .getNextIncludedTime(new Date().getTime())
)

If i am using code (with quartz) its always showing current time in date
format.

Any help on the above issue would be highly apprieciated?



--
View this message in context: http://camel.465427.n5.nabble.com/Problem-in-converting-Cron-expression-into-proper-date-format-tp5739498p5739602.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem in converting Cron expression into proper date format.

Posted by gquintana <ge...@gmail.com>.
With Quartz


With Spring




--
View this message in context: http://camel.465427.n5.nabble.com/Problem-in-converting-Cron-expression-into-proper-date-format-tp5739498p5739527.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem in converting Cron expression into proper date format.

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You should ask on user forum for the cron library you use, eg if its
quartz, then on some quartz user forum.


On Wed, Sep 18, 2013 at 10:26 AM, loganathan <lo...@gmail.com> wrote:
> Can you help me to covert cronexpression into proper date format?our need is
> whatever cron expression we passes will have to get proper date format
> whether its a past time cronexpression or future time cronexpression.
>
> for example assume we have cron expression like 0 0 12 1/1 * ? * due to some
> reasons my server stopped on that time again its get started after 12'0
> clock on that scenario if  i am using getNextValidTimeAfter its showing date
> as next day actually that is not my requirement.My requirement is to get the
> missed cronexpession in proper date format.Any help on the issue would be
> highly appreciated?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-in-converting-Cron-expression-into-proper-date-format-tp5739498p5739712.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Problem in converting Cron expression into proper date format.

Posted by loganathan <lo...@gmail.com>.
Can you help me to covert cronexpression into proper date format?our need is
whatever cron expression we passes will have to get proper date format
whether its a past time cronexpression or future time cronexpression.

for example assume we have cron expression like 0 0 12 1/1 * ? * due to some
reasons my server stopped on that time again its get started after 12'0
clock on that scenario if  i am using getNextValidTimeAfter its showing date
as next day actually that is not my requirement.My requirement is to get the
missed cronexpession in proper date format.Any help on the issue would be
highly appreciated? 



--
View this message in context: http://camel.465427.n5.nabble.com/Problem-in-converting-Cron-expression-into-proper-date-format-tp5739498p5739712.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem in converting Cron expression into proper date format.

Posted by loganathan <lo...@gmail.com>.
Thanks for quick response Claus.we are using two jars quartz-1.8.6.jar and
camel-quartz-2.9.2.jar.I don't see any method as next expected fire time
inside both org.quartz.CronExpression and org.quartz.CronTrigger API.

Any help on this? 



--
View this message in context: http://camel.465427.n5.nabble.com/Problem-in-converting-Cron-expression-into-proper-date-format-tp5739498p5739540.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem in converting Cron expression into proper date format.

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

What Cron library do you use? If you use Quartz or Spring then I
suggest to check their API as they may have methods to get the next
expected fire time or something like that.



On Mon, Sep 16, 2013 at 8:14 AM, loganathan <lo...@gmail.com> wrote:
> I have cron expression like 0 05 14 * * ? to start the route.But what my
> requirement is i have to convert the same cron expression into proper date
> format.The following is the code used for converting cron expression into
> date format.
>
>  CronExpression cronExpression = new CronExpression("0 05 14 * * ?");
>  Date date1 = cronExpression.getNextValidTimeAfter(new Date());
> System.out.println("date1 date is>>>>>>..."+date1);
>
> Note:My requirement is not next valid,invalid,next,current time for the cron
> expression that i have mentioned above.need is exact date format eg:Mon Sep
> 16 14:15:00 IST 2013 for the above cron expression.
>
> Like that whatever cron expression i have pass i need exact date format for
> the cron expression.
>
> Very Urgent.Anyone help is highly appreciated?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-in-converting-Cron-expression-into-proper-date-format-tp5739498.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen