zoukankan      html  css  js  c++  java
  • 列出cron的下几次运行时间

    static void Main(string[] args)
            {
                           
                while(true)
                {
                    var corn = Console.ReadLine();
                     var s=getCronSchdule(corn, 10, DateTimeOffset.Now);
                    Console.WriteLine(s);
                }
           
    
            }
    
            /// <summary>
            /// Corn表达式的运行时间
            /// </summary>
            /// <param name="cron">表达式</param>
            /// <param name="times">计算次数</param>
            /// <param name="startTime">开始时间</param>
            /// <returns></returns>
            public static String getCronSchdule(String cron, int times, DateTimeOffset startTime)
            {
                String timeSchdule = "";
                if (!CronExpression.IsValidExpression(cron))
                {
                    return "Cron is Illegal!";
                }
                try
                {
    
                    ITrigger trigger1 = TriggerBuilder.Create().WithCronSchedule(cron)//.StartAt(DateTimeOffset.UtcNow)
                    .Build();
                    DateTimeOffset? LastTime = startTime;
                    //Console.WriteLine(LastTime.ToString());
                    for (int i = 0; i < times; i++)
                    {
                        DateTimeOffset? s = trigger1.GetFireTimeAfter(LastTime);
                        LastTime = s;
                        Console.WriteLine(((DateTimeOffset)s).AddHours(8).ToString());
                    }
    
    
                }
                catch (Exception e)
                {
                    timeSchdule = "unKnow Time!";
                }
                return timeSchdule;
            }
    

      

  • 相关阅读:
    抽象类使用细节
    super关键字
    JDK,JRE,JVM三者之间的爱恨情仇
    LinkedHashSet
    HashSet扩容成红黑树机制
    Set之HashSet
    finally关键字
    Hashcode方法
    equals方法和==的区别
    LinkedList
  • 原文地址:https://www.cnblogs.com/xinzhyu/p/10538593.html
Copyright © 2011-2022 走看看