string sampleCronString = "1,3,7,12-15 18 * * *"; string[] fields = sampleCronString.Split(' '); List<int> minutes = GetValues(fields[0],60); if (minutes.Contains(DateTime.Now.Minute)) { //Possible match - go on and do the same for hours (call GetValues() again with fields[1] and '24' }with
List<int> GetValues(string s,int itemcount) { List<int> list = new List<int>(); List<string> items = s.Split(',').ToList(); foreach (string s2 in items) { if (s2 == "*") { //All items for (int i = 1; i <= itemcount; i++ ) { list.Add(i); } } else if (s2.Contains('-')) { //Range string[] s3 = s2.Split('-'); int start = Int32.Parse( s3[0]); int end = Int32.Parse(s3[1]); for (int i = start; i <= end; i++) { list.Add(i); } } else { //Single Item list.Add(Int32.Parse(s2)); } } return list; }Needs a lot of work but....