110,537
社区成员
发帖
与我相关
我的任务
分享
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"));
}
}
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"));
}
}
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();
}
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++;
}
}
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++;
}
}