我从重复服务获得了时间表数据。 如何以用户友好的方式解析格式? 这是样本计划格式。 0 13? * MON * 请告诉我如何获得时间表格式的定义。
谢谢。
Repeating.Service rService = Repeating.service(client, trigger.getId());
Repeating repeat = rService.getObjectForRepeating();
System.out.println("repeat schedule : " + repeat.getSchedule());
答案 0 :(得分:0)
schedule属性的格式为Cron格式。
计划属性:
cron格式的计划。这是在UTC时区运行的。 创建需要 类型: 串
下一个java脚本可以帮助你。
/**
* This script retrieves the Repeating trigger policies for a SoftLayer_Scale_Policy, then
* it gets the schedule attribute and parses the value (Cron format) to human readable format.
*
* Important manual pages:
* @see http://sldn.softlayer.com/reference/services/SoftLayer_Scale_Policy/getRepeatingTriggers
* @see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Scale_Policy_Trigger_Repeating
*
* @license <http://sldn.softlayer.com/wiki/index.php/License>
* @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
package SoftLayer_Java_Scripts.Examples;
import com.softlayer.api.*;
import com.softlayer.api.service.scale.Policy;
import com.softlayer.api.service.scale.policy.trigger.Repeating;
import java.util.Date;
import java.util.List;
import org.quartz.CronExpression;
public class GetObjectScalePolicyTriggerRepeating
{
public static void main( String[] args )
{
// Fill with your valid data here.
String user = "set me";
String apiKey = "set me";
long scalePolicyId = 1234;
ApiClient client = new RestApiClient().withCredentials(user, apiKey);
Policy.Service service = Policy.service(client, scalePolicyId);
try
{
List<Repeating> result = service.getRepeatingTriggers();
for(Repeating rep : result) {
String cronValue = rep.getSchedule();
System.out.println("Original value: " + cronValue);
// Fixing format in order to display the schedule.
String patch = "* " + cronValue;
// Using the next library: http://www.quartz-scheduler.org/api/2.2.1/org/quartz/CronExpression.html
CronExpression cron = new CronExpression(patch);
// Returns the next date/time after the given date/time which satisfies the cron expression.
// (i.e. the next time it's going to be triggered)
System.out.println("Parsed value: " + cron.getNextValidTimeAfter(new Date()));
}
}
catch(Exception e)
{
System.out.println("Script failed, review the next message for further details: " + e);
}
}
}
下一个链接包含有关cron格式的信息:
http://www.nncron.ru/help/EN/working/cron-format.htm
http://www.quartz-scheduler.org/api/2.2.1/org/quartz/CronExpression.html