• 列出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;
            }
    

      

  • 相关阅读:
    forward和redirect的区别
    转 jsp中 session的简单用法
    20_学生选课数据库SQL语句练习题1
    _学生选课数据库SQL语句练习题
    输入输出2
    接口提
    输入输出流3
    获取当前时间并显示在网页上
    简单的权限管理
    java关于时间
  • 原文地址:https://www.cnblogs.com/xinzhyu/p/10538593.html
Copyright © 2020-2023  润新知