Convert cron expression into nice description strings? Is there a library for JAVA and Objective-C? [closed]

本小妞迷上赌 提交于 2019-11-26 20:58:55

问题


I am looking for a parser that converts a cron expression like 45 17 7 6 * * into Every year, on June 7th at 17:45 The parser should be adjustable to other languages. German for the first step.

Is there a library for a

  • JAVA based Android project
  • Objective-C based Iphone project.

See here for the usecase.


回答1:


cronTrigger.getExpressionSummary()

Example:

    CronTrigger t = new CronTrigger();
    t.setCronExpression("0 30 10-13 ? * WED,FRI");
    System.out.println(""+t.getExpressionSummary());

Output:

seconds: 0
minutes: 30
hours: 10,11,12,13
daysOfMonth: ?
months: *
daysOfWeek: 4,6
lastdayOfWeek: false
nearestWeekday: false
NthDayOfWeek: 0
lastdayOfMonth: false
years: *
  • Api Java Doc



回答2:


In Java, have a look into cron4j http://www.sauronsoftware.it/projects/cron4j/

You will find the parser you need but then you have to write your code to print the string as you need it. Start by creating a SchedulingPattern object:

new SchedulingPattern("0 30 10-13 ? * 1,2,5")



回答3:


You may find cron-utils useful for this task, since provides human readable descriptions in various languages and does not require a fully fledged scheduler to provide them. Supports multiple cron formats. Below a code snippet from the docs:

//create a descriptor for a specific Locale
CronDescriptor descriptor = CronDescriptor.instance(Locale.UK);

//parse some expression and ask descriptor for description
String description = descriptor.describe(parser.parse("*/45 * * * * *"));
//description will be: "every 45 seconds"


来源:https://stackoverflow.com/questions/4469276/convert-cron-expression-into-nice-description-strings-is-there-a-library-for-ja

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!