解决方案 »

  1.   

    DateTime允许做加法的。另外C#里有个TimeSpan是用来表示时间间隔的,可以用TimeSpan表示你的时间间隔,然后往DateTime上加就好了
      

  2.   

    public Form1()
            {
                InitializeComponent();            this.richTextBox1.Dock = DockStyle.Fill;            DateTime start = DateTime.Parse("2014-09-12 02:08:20");
                DateTime stop = DateTime.Parse("2014-09-13 12:22:20");            TimeSpan span = new TimeSpan(0, 0, 10, 0);            Int64 count = start.Ticks / span.Ticks;
                DateTime first = new DateTime((count + 1) * span.Ticks);
                count = stop.Ticks / span.Ticks;
                DateTime last = new DateTime((count + 1) * span.Ticks);            List<DateTime> list = new List<DateTime>();
                list.Add(start);
                for (DateTime temp = first; temp <= last; temp += span) {
                    list.Add(temp);
                }
                list.Add(stop);            Int32 warp = 1;
                foreach (DateTime time in list) {
                    richTextBox1.AppendText(time.ToString("yyyy-MM-dd hh:mm:ss"));
                    if ((warp % 8) != 0)
                        richTextBox1.AppendText("\t");
                    else
                        richTextBox1.AppendText("\n");
                    warp++;
                }
            }
    运行效果
      

  3.   

     static void Main(string[] args)
            {
                DateTime begin = DateTime.ParseExact("2014-09-12  02:08:20", "yyyy-MM-dd  HH:mm:ss", null);
                DateTime end = DateTime.ParseExact("2014-09-13  12:22:20", "yyyy-MM-dd  HH:mm:ss", null);            List<DateTime> timelist = new List<DateTime>();
                while (begin < end)
                {
                    int hour = begin.Hour;
                    while (hour == begin.Hour && begin < end)
                    {
                        if (begin.Minute % 10 == 0 && (begin.Second == 1 || begin.Second == 0))
                        {
                            if (begin.Minute == 30 && begin.Second == 1)
                            {
                                begin = begin.AddMinutes(29).AddSeconds(59);
                                break;
                            }
                            timelist.Add(begin);
                            if (begin.Second == 1)
                                begin = begin.AddMinutes(9).AddSeconds(59);
                            else
                                begin = begin.AddSeconds(1);
                        }
                        else
                        {
                            timelist.Add(begin);
                            int tempmin = 10 - begin.Minute % 10;
                            int tempsecond = begin.Second;
                            begin = begin.AddMinutes(tempmin).AddSeconds(tempsecond * -1);
                        }
                    }
                }
                if (begin != end)
                    timelist.Add(end);            timelist.ForEach(x => Console.WriteLine(x));
                Console.ReadKey();
            }
      

  4.   


            public static void GetTimeSpan()
            {
                DateTime starttime = Convert.ToDateTime("2014-09-12  02:08:20");
                DateTime endtime = Convert.ToDateTime("2014-09-13  12:22:20");            List<DateTime> list = new List<DateTime>();
                for (DateTime i = starttime; i < endtime; i = i.AddMinutes(1))
                {
                    if (i.Minute % 10 == 0)
                    {
                        if (list.Count == 0 && i != starttime)
                        {
                            list.Add(starttime);
                        }
                        list.Add(i);
                    }
                }
                if (list[list.Count - 1] != endtime)
                {
                    list.Add(endtime);
                }            foreach (DateTime time in list)
                {
                    Console.WriteLine(time.ToString("yyyy-MM-dd hh:mm:ss"));
                }        }
      

  5.   


        public static void GetTimeSpan()
            {
                DateTime starttime = Convert.ToDateTime("2014-09-12  02:08:20");
                DateTime endtime = Convert.ToDateTime("2014-09-13  12:22:20");
     
                List<DateTime> list = new List<DateTime>();
                for (DateTime i = starttime; i <= endtime; i = i.AddMinutes(1))
                {
                    if (i.Minute % 10 == 0)
                    {
                        if (list.Count == 0 && i != starttime)
                        {
                            list.Add(starttime);
                        }
                        list.Add(i);
                    }
                }
                if (list[list.Count - 1] != endtime)
                {
                    list.Add(endtime);
                }
     
                foreach (DateTime time in list)
                {
                    Console.WriteLine(time.ToString("yyyy-MM-dd hh:mm:ss"));
                }
     
            }
      

  6.   

    看完6楼的代码,我发现我少了一部分,下面是重新修改的
    public Form1()
            {
                InitializeComponent();            this.richTextBox1.Dock = DockStyle.Fill;            DateTime start = DateTime.Parse("2014-09-12 02:08:20");
                DateTime stop = DateTime.Parse("2014-09-13 12:22:20");            TimeSpan span = new TimeSpan(0, 0, 10, 0);            Int64 count = start.Ticks / span.Ticks;
                DateTime first = new DateTime((count + 1) * span.Ticks);
                count = stop.Ticks / span.Ticks;
                DateTime last = new DateTime((count + 1) * span.Ticks);            List<DateTime> list = new List<DateTime>();
                list.Add(start);
                for (DateTime temp = first; temp <= last; temp += span) {
                    list.Add(temp);
                    list.Add(temp.AddSeconds(1));
                }
                list.Add(stop);            Int32 warp = 1;
                foreach (DateTime time in list) {
                    richTextBox1.AppendText(time.ToString("yyyy-MM-dd hh:mm:ss"));
                    if ((warp % 2) != 0)
                        richTextBox1.AppendText("\t");
                    else
                        richTextBox1.AppendText("\n");
                    warp++;
                }
            }效果差不多,只是计算方式上有点区别,看你需要了